PythonMastery

BMI calculator program in Python

Read weight in kilograms and height in metres, calculate the body mass index (weight / height²), and print the standard category.

Body mass index (BMI) is weight in kilograms divided by the square of height in metres.

The program

python
weight = float(input("Weight (kg): "))
height = float(input("Height (m): "))

bmi = weight / height ** 2

if bmi < 18.5:
    category = "underweight"
elif bmi < 25:
    category = "healthy weight"
elif bmi < 30:
    category = "overweight"
else:
    category = "obese"

print(f"BMI = {bmi:.1f} ({category})")

Typed in this example: 70, 1.75. Press Run to type your own.

output
Weight (kg): 70
Height (m): 1.75
BMI = 22.9 (healthy weight)

How it works

Learn the idea: Input & Output: Talking to Your User, Control Flow: Conditionals