+ 1
I need help with this bmi code. This is made in Python.
So it works fine if i dont have the user input but if i do in line 4 it says error Unsupported operand types for ** or pow(): 'str' and 'int' This is line 4 bmi = weight_kg / (height_m ** 2 Heres the code name = input("please enter your name") height_m = input("please enter your height in meters") weight_kg = input("please enter your weight in kg") bmi = weight_kg / (height_m ** 2) print( "bmi: ") if bmi < 25: print(name) print("is not overweight") else: print(name) print("is overweight")
2 ответов
+ 6
Actually your output is in string format and +,-,÷,* and ** don't work string format variable so you need to convert into int or may be into float like this.
weight_kg=int(input("please enter your weight in kg"))
+ 5
You need to convert the variable to integer type first,
use this :
name = int(input())
height = int(input())
weight = int(input())