How to Build a Simple BMI Calculator in Python
- Anubhav Somani
- 5 days ago
- 2 min read

Let's build a BMI (Body Mass Index) Calculator. This is a practical and useful project that's great for beginners to practice getting numeric input, performing calculations, and using conditional logic to classify the results.
First, here is the explanation of how the project is built.
How the "BMI Calculator" is Made
The Core Idea: The goal is to create a program that calculates a person's Body Mass Index based on their weight and height. It will then interpret this value to tell the user whether they fall into standard weight categories (e.g., underweight, normal weight, overweight).
The BMI Formula: The standard formula for BMI is: BMI = weight (kg) / (height (m))^2 It's crucial to note the units: weight must be in kilograms and height must be in meters.
Getting User Input Safely: We need to ask the user for two pieces of information: their weight in kilograms and their height in centimeters.
We'll use the input() function for both. Since the input will be text, we must convert it to a number using float() to allow for decimal values.
This conversion can fail if the user types text instead of a number. To prevent a crash, we'll wrap the input-gathering code in a try-except ValueError block. If an error occurs, we'll print a friendly message and stop the program.
Unit Conversion: The user will enter their height in centimeters because that's more common, but the formula requires meters. Inside the code, we'll convert the height from centimeters to meters by dividing it by 100.
Performing the Calculation: Once we have the weight in kg and the height in meters, we can implement the formula in Python. The height squared is simply height_in_meters * height_in_meters.
Classifying the Result: A BMI number by itself isn't very helpful, so we need to tell the user what it means. We'll use a series of if, elif (else if), and else statements to check the calculated BMI against the standard categories:
If BMI is less than 18.5, the category is "Underweight".
If BMI is between 18.5 and 24.9, the category is "Normal weight".
If BMI is between 25 and 29.9, the category is "Overweight".
If BMI is 30 or greater, the category is "Obesity".
Displaying the Final Output: Finally, we'll use a formatted f-string to print a clear message to the user, showing them their calculated BMI (rounded to two decimal places for readability) and the corresponding weight category.
Comments