[Tutor] (no subject)
Joel Goldstick
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
> """
> inchtocm.py
>
> """
>
> 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
>
> inches = None
> while True:
> try:
> 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.")
> break
> 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
> 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:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130211/c028eb0a/attachment-0001.html>
More information about the Tutor
mailing list