[Python-Dev] problem with python 3.1
James Mills
prologic at shortcircuit.net.au
Wed Sep 15 21:39:30 EDT 2010
(Posting to python general discussion).
On Thu, Sep 16, 2010 at 10:17 AM, João Vitor <johnvmo at hotmail.com> wrote:
> I made a program that, according to my teacher, is correct but is not
> running properly.
> The program is really simple:
> import math
> x = input ("Coloque o valor do primeiro cateto:")
> y = input ("Coloque o valor do segundo cateto:")
> z = x**2
> w = y**2
> soma = z + w
> h = math.sqrt (soma)
> print = "O valor da hipotenusa é:", h
> But after I put the value of x and y this error appears:
> Traceback (most recent call last):
> File "C:/lista03.py", line 4, in <module>
> z = x**2
> TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
> My teacher said the program ran normally in his computer, but in my it
> doesn't!
> why?
You're teacher has clearly overlooked that you must convert the values
of x and y to
int's using either:
x = int(input(...))
or
x = int(x)
You cannot perform (most) mathematical operators where the operands
are of different types (in Python)
eg: str and int
cheers
James
PS: Please post questions like this to either the tutor or general
python mailing list(s).
--
-- James Mills
--
-- "Problems are solved by method"
More information about the Python-list
mailing list