I am getting this error unsupported operand type(s) for ** or pow(): 'str' and 'int'

Question:

Why I am getting this error I am creating a bmi calculator:

unsupported operand type(s) for ** or pow(): 'str' and 'int'

Code snippet:

Height= input("Enter Height in meter")
Weight= input (" Enter Weight in Kg ")
Result = int(weight)/int(height**2)
Print(result)
Asked By: Bhhsha Shhsis

||

Answers:

input() returns a string, which has to be converted into a number.

So like

height= int(input("Enter Height in meter"))
weight= int(input (" Enter Weight in Kg "))
result = weight/(height**2)
print(result)
Answered By: Leif Messinger LOAF

Whatever you enter in input() gets converted into a string.
You can convert height into an integer int(height)**2 or simply convert input to integer that instance int(input("Enter Height in meter"))

Answered By: user15801675

I am getting the same error aslways when I work with inputs.
The best answer is to call a function. Look at my work below.
def float_int(asked):
if "." in asked:
asked = float(asked)
else:
asked = int(asked)
And the next time you use an input, call it a name such as "ask_one" and insert it into the agrument. Its supposed to work. Look below again.
ask_one = input("Insert Value")
float_int(ask_one)
Hope this helped(:

Answered By: DUDEPERFECT
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.