Python Program to Calculate BMI
Beginner · Basics
Body Mass Index (BMI) is a rough check of whether a person's weight suits their height: the weight in kilograms divided by the square of the height in metres. This program works out the BMI and places it in one of the standard adult categories: underweight, normal weight, overweight or obese.
Program
BMI: 24.3 Category: Normal weight
How it works
height ** 2squares the height, and dividing the weight by it gives the BMI in kilograms per square metre.round(bmi, 1)keeps one decimal place for display, while the full value is used for the checks.- The
if/elifchain tests the cut-offs from lowest to highest, so each check only needs an upper limit: by the timebmi < 25is tested, the BMI is already known to be at least 18.5. - These are the WHO cut-offs for adults; for children and teenagers, BMI is read from charts made for their age instead.
Another way to write it
For several people, with height in centimetres
Aditi has a BMI of 17.6 Rahul has a BMI of 24.3 Vikram has a BMI of 30.9
Most people know their height in centimetres, so the function divides it by 100 first. Putting the formula in a function also makes it easy to work out the BMI of a whole list of people.
Try it yourself
Change the cut-offs to the ones often used for Asian adults (overweight from 23, obese from 25) and see how the category for this sample changes.
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises