简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM