231. Python Program to Calculate BMI and Show Its Category
EasyPhase 1 · Warm-up
You know input(), float() and if with elif. That is all you need here.
Overview
BMI means body mass index. It is one number that compares your weight with your height. Health apps and doctors use it as a quick first check.
Problem Statement
Kofi wants a small BMI tool for a phone. The formula is: BMI = weight ÷ (height × height). The weight is in kilograms and the height is in metres.
The BMI falls into one of 4 bands:
- Less than 18.5 is Underweight.
- 18.5 or more, but less than 25, is Normal.
- 25 or more, but less than 30, is Overweight.
- 30 or more is Obese.
Read the weight and the height. Print the BMI with 2 decimal places, then the category, in this format:
BMI: <bmi>
Category: <category>
Steps
- Read the weight and the height as decimal numbers.
- Work out the BMI: the weight divided by the height times the height.
- Find the band: check below 18.5 first, then below 25, then below 30. Anything else is Obese.
- Print the BMI with 2 decimal places, then the category.
Examples
Example 1. Input:
70
1.75
gives:
BMI: 22.86
Category: Normal
Why: 1.75 × 1.75 = 3.0625, and 70 ÷ 3.0625 = 22.857..., which shows as 22.86. It is 18.5 or more and less than 25, so it is Normal.
Example 2. Input:
100
2
gives:
BMI: 25.00
Category: Overweight
Why: 2 × 2 = 4, and 100 ÷ 4 = 25. A BMI of exactly 25 is not less than 25, so it is Overweight, not Normal.
Input
Two lines:
- The weight in kilograms, a number more than 0 (it may have a decimal point, like
62.5). - The height in metres, a number more than 0 (like
1.75).
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
Two lines: BMI: <bmi> with 2 decimal places, then Category: <category>. The category is one of Underweight, Normal, Overweight or Obese. The tests try 6 different inputs, also a BMI of exactly 18.5 and exactly 30.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.