87.5k views
2 votes
How do we calculate the BMI in python?
the formula is kg/m²

User Marlowe
by
3.4k points

1 Answer

7 votes

Answer:

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

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

BMI = weight / (height/100)**2

print(f"You BMI is {BMI}")

Step-by-step explanation:

The python code for calculating BMI is as follows -

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

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

BMI = weight / (height/100)**2

print(f"You BMI is {BMI}")

Some conditions can also be added such as

if BMI <= 15:

print("You are underweight.")

elif BMI <= 30:

print("You are healthy.")

elif BMI <= 40:

print("You are over weight.")

User Roi Divon
by
3.9k points