[Tutor] ValueError

Johnson Tran aznjonn at me.com
Tue May 3 12:30:37 CEST 2011


Hi All, 

i am trying to create a program module with two functions (conversion inches to centimeters then centimeter to inches, I have my program working although I am trying to adda Value Error function to my program but cannot seem to it to work:


def Conversion():
    print "This program converts the first value from inches to centimeters and second value centimeters to inches."
    print "(1 inch = 2.54 centimeters)"
    inches = input("Enter length in inches: ")
    centimeters = 2.54 * inches
    print "That is", centimeters, "centimeters."

    centimeters = input("Enter length in centimeters: ")
    inch = centimeters / 2.54
    print "That is", inch, "inches."

    except ValueError:
        print "Invalid digit, please try again."
        
Conversion()



Any advice would be great, thanks!

JT


More information about the Tutor mailing list