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)
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)
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"))
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(:
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)
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)
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"))
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(: