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
height ** 2is calculated before the division, so the formula is weight / (height × height).- The
if/elif/elsechain checks the ranges in order and stops at the first one that is true. The ranges are the standard adult ones used by the WHO. - Height is in metres: 175 cm is
1.75. Typing175would give a BMI of about 0.002.