简体   繁体   中英

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

Just started coding 2 days ago and decided to build a little BMI calculator, but I keep getting this error, I've tried everything I could find, but had no sucess, can anyone help me understand what I'm doing wrong here? thanks in advance! Image of my coding and error

Your typecasting is not assigned to a variable and you need height and weight in float.

height = float(input("Enter your height in m: "))
weight = float(input("Enter your weight in kg: "))

BMI = weight / (height**2)

Change your code to:

height = float(input(...))
weight = float(input(...))

You're not actually setting the result of float() to the variable.

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