[Tutor] ValueError

Nitin Pawar nitinpawar432 at gmail.com
Tue May 3 12:41:33 CEST 2011


When you take input its bydefault is in string format

you might want to typecast and validate teh input

On Tue, May 3, 2011 at 4:00 PM, Johnson Tran <aznjonn at me.com> wrote:

> 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
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110503/6305a0f4/attachment.html>


More information about the Tutor mailing list