[Tutor] (no subject)
joel.goldstick at gmail.com
Mon Feb 11 17:12:33 CET 2013
First, pick a good subject header.
By having caught excep ValueError in your mainline code you lose the
opportunity to find out where it came from. If you comment it out you will
see that the function inchtocm(inches) uses inches_number1 in its code. So
you are ignoring the inches that you passed in. Is that what you want?
On Mon, Feb 11, 2013 at 10:58 AM, Pravya Reddy <pravyareddy at gmail.com>wrote:
> Can you please help me with the code.
> #!/usr/bin/env python
> def Inchtocm(inches):
> """Returns 2.54 * inches"""
> return (2.54 * float(inches_number1))
The line above here is suspect since you likely want to return 2.54 *
> inches = None
> while True:
> inches_number1 = input(input("How many inches you want to convert:
> inches = float(inches_number1)
> print ("You got", Inchtocm(inches), "cm.")
> print ("You converted", inches, "inches to cm.")
> except ValueError:
> print ("This is not a number!")
> The code is incomplete and i am not getting a proper output:
> How many inches you want to convert: 455
> This is not a number!
> How many inches you want to convert:
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor