Hey there,
I have this code below (in to cm conversion) and I want to have the user try
again if they enter in a non integer. What am I missing:
ConversionConstant = 2.54
def CalculateCentimeters(inches):
return ConversionConstant * inches
def CalculateInches(centimeters):
return centimeters / ConversionConstant
try:
value = float(raw_input('Please enter a number: '))
except ValueError:
print "Not a valid number."
conversion_type = raw_input('Please enter a unit of measure (C/I)? ')
output = None
if conversion_type == 'C':
output = CalculateInches(value)
print "That's", output, "inches!"
elif conversion_type == 'I':
output = CalculateCentimeters(value)
print "That's", output, "centimeters!"
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor