class Length:
__metric = {"mm" : 0.001, "cm" : 0.01, "m" : 1, "km" : 1000,
"in" : 0.0254, "ft" : 0.3048, "yd" : 0.9144,
"mi" : 1609.344 }
def __init__(self, value, unit = "m" ):
self.value = value
self.unit = unit
def convert(self, target_unit="m"):
if self.unit == target_unit:
value = self.value
else:
value = self.value * Length.__metric[self.unit]
value /= Length.__metric[target_unit]
return value