[Tutor] What is wrong my code?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Mar 24 22:45:25 CET 2006

> leg1 = raw_input('Enter the first leg of the triangle:
> ')
> leg2 = raw_input('Enter the second leg of the
> triangle: ')

Hi Hoffmann,

leg1 and leg2 here are strings, because raw_input() is guaranteed to
return strings.

You'll want to do something to turn those strings into numbers, since the
hypotenuse() function:

> result = hypotenuse(leg1, leg2)

is going to break on non-numeric input.

I think you'll find the float() function useful: it's a function that can
take strings and return floating-point numbers.  For example:

>>> float("3.1415926")
>>> float("7")

Good luck to you!

More information about the Tutor mailing list