[Tutor] Help With Code
jordan smallwood
jsmallwood82 at yahoo.com
Thu May 1 02:18:43 CEST 2014
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!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140430/97ff4f6b/attachment-0001.html>
More information about the Tutor
mailing list