#!/usr/bin/env python3
# coding: utf8
'''
Created on November 6th, 2017
@author: Geetanjali
'''
def convert_length(length, unit):
"""
:param length: length to be converted to various units
:param unit: the of unit the length entered
:return: returns a dictionary with various units as keys, and the value of length in that unit as values
"""
length_dict = {}
if(unit == "meter"):
length_dict["miles"] = (0.000621)*length
length_dict["inches"] = (39.370079)*length
length_dict["feet"] = (3.28084)*length
length_dict["yards"] = (1.093613)*length
elif(unit == "yard"):
length_dict["meters"] = (0.9144)*length
length_dict["miles"] = (0.000568182)*length
length_dict["inches"] = (36)*length
length_dict["feet"] = (3)*length
elif(unit == "mile"):
length_dict["meters"] = (1609.34)*length
length_dict["yards"] = (1760)*length
length_dict["inches"] = (63360)*length
length_dict["feet"] = (5280)*length
elif(unit == "inch"):
length_dict["meters"] = (0.0254)*length
length_dict["miles"] = (1.57828e-5)*length
length_dict["yards"] = (0.0277778)*length
length_dict["feet"] = (0.0833333)*length
elif(unit == "foot"):
length_dict["meters"] = (0.3048)*length
length_dict["miles"] = (0.000189394)*length
length_dict["inches"] = (12)*length
length_dict["yard"] = (0.333333)*length
return length_dict
def convert_SI(length):
"""
:param length: length to be converted to SI units
:return SI_length_dict: returns a dictionary with various SI units as keys, and the value of length in that unit as values
"""
SI_length_dict = {}
SI_length_dict["nm"] = 10**9*length
SI_length_dict["um"] = 10**6*length
SI_length_dict["mm"] = 10**3*length
SI_length_dict["cm"] = 10**2*length
SI_length_dict["km"] = 10**(-3)*length
return SI_length_dict
if __name__ == '__main__':
length = float(input("Please input a length (number only): "))
unit = input("Please type a unit system (meter, mile, inch, foot, yard): ")
length_dict = convert_length(length, unit)
#if the entered length is in meters, we directly the function convert_SI() on it. Else, we first find its value in meters and then call convert_SI()
if(unit == "meter"):
SI_length_dict = convert_SI(length)
else:
SI_length_dict = convert_SI(length_dict["meters"])
#Printing the value of length in various units of measurement
result = []
for key, value in length_dict.items():
result.append(str(value)+" "+str(key))
print(result)
#Printing the value of length in various SI units of measurement
result = []
for key, value in SI_length_dict.items():
result.append(str(value)+" "+str(key))
print(result)