In this tutorial, we will understand what Body Mass Index or BMI is, how we can create a BMI calculator in the Python programming language.
Let’s get started!
What is Body Mass Index (BMI)?
BMI
is dependent on a person’s height and weight. Also, people are classified as being underweight, overweight, or even obese based on their BMI value.

BMI can be used as a substitute for taking precise measurements of body fat percentages. Furthermore, BMI is a low-cost and simple way to check for those who may be at risk of health problems due to their weight.
BMI Calculator Implementation in Python
BMI is determined by dividing a person’s weight in kilograms twice by their height in meters, Here is the code for the BMI calculator written in Python:
h=float(input("Enter your height in meters: "))
w=float(input("Enter your Weight in Kg: "))
BMI=w/(h*h)
print("BMI Calculated is: ",BMI)
if(BMI>0):
if(BMI<=16):
print("You are very underweight")
elif(BMI<=18.5):
print("You are underweight")
elif(BMI<=25):
print("Congrats! You are Healthy")
elif(BMI<=30):
print("You are overweight")
else:
print("You are very overweight")
else:
print("enter valid details")
Let us understand the whole code line by line.
Line 1
and Line 2
– Taking input for height and weight of the person
Then we check if the BMI is greater than 0 or not as neither the weight nor the height can be negative hence BMI value can never be less than 0.
Now according to the BMI value, the person is categorized into underweight, healthy, and overweight using the if-else conditional statements.
Some Sample Outputs


Conclusion
I hope you understood BMI and how to implement and calculate the same in python. Try it yourself!
Happy Coding! 😇
Want to learn more? Check out the tutorials mentioned below:
- How to Calculate Dot Product in Python?
- 4 Methods to Calculate Square Root in Python
- How to Calculate Summary Statistics in Python?
- How to Compute Distance in Python? [ Easy Step-By-Step Guide ]