TypeError: can't multiply sequence by non-int of type 'str' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: can't multiply sequence by non-int of type 'str' (/thread-19436.html) |
TypeError: can't multiply sequence by non-int of type 'str' - rregorr - Jun-28-2019 I am using the follow code to calculate the hypotenuse and legs of a rectangle triangle. If any one of the 3 given values(a, b ou c) is "x", it would be to calculate other variables. But, when I run the code, I get the message bellow: Traceback (most recent call last): File "main.py", line 7, in <module> quadradosA_B = int(b*b)+int(c*c) TypeError: can't multiply sequence by non-int of type 'str' import math a = input('Informe a hipotenusa: ') b = input('Informe o Cateto A: ') c = input('Informe o Cateto B: ') if (a == 'x'): quadradosA_B = int(b*b)+int(c*c) hipotenusa = math.sqrt(quadradosA_B) print('A hipotenusa é: ', hipotenusa) elif (b == 'x'): quadradoCatetoB = int(a*a)-int(c*c) CatetoB = math.sqrt(quadradoCatetoB) print('Cateto B vale: ', CatetoB) elif (c == 'x'): quadradoCatetoC = int(a*a)-int(b*b) CatetoC = math.sqrt(quadradoCatetoC) print('Cateto C vale: ', CatetoC) RE: Erros message - ichabod801 - Jun-28-2019 The input function returns a string. You need to convert that value to a number before doing math with it. So rather than int(b * b) you want something like int(b) * int(b) .
RE: Erros message - Yoriz - Jun-28-2019 input returns a string use int or float on the returned string to do calculations.
|