GITHUB REPO | FOLLOW ME ON -> TWITTER | LINKEDIN
How to Create a BMI Calculator Using Python: Step-by-Step Guide
Body Mass Index (BMI) is a body fat measurement based on height and weight that is applicable to both adult males and females. In this article, we’ll look at how to make a BMI calculator in Python. We will go through each code block in detail, including both the feature used in the code and the example output.
Python is an advanced programming language with numerous features that make it simple to create complicated programs. We will use Python’s input()
function to receive user input and if/else statements to compare and report the BMI status in this project.
Step-by-Step Explanation of Code
The first thing we need to do is set up our Python BMI Calculator. Open up your preferred code editor, create a new file, and save it with a descriptive name such as “bmi_calculator.py.
”
We will start by displaying a welcome message to the user.
print("\nWelcome to my BMI Calculator\n")
Then, we will use the input()
function to get the user’s height and weight as inputs.
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
Next, we will use the formula BMI = weight / height ** 2
to calculate the user’s BMI.
bmi = weight / height ** 2
Finally, we will use the if/else statements to compare the calculated BMI and print the appropriate BMI status.
if bmi < 18.5:
print("You're Underweight")
elif bmi < 25:
print("You're Normal Weight")
elif bmi < 30:
print("You're Slightly Overweight")
elif bmi < 35:
print("You're Obese")
else:
print("You're Clinically Obese")
Here is the full code.
Sample output
We learnt how to make a BMI calculator as a beginner in Python in this article. We explored Python features utilized in the project, such as the input()
function and if/else statements. This blog provided a step-by-step explanation of each code block, as well as the full code on GitHub Gist. I hope you found this article useful in your ongoing effort to learn Python programming.
This article is a part of my Python Project Journal. Please have a visit to my journal. Thank you!