Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

BMI Calculator in Python – A Complete Step-By-Step Tutorial

  • Isha BansalIsha Bansal
  • September 30, 2021
  • Python Programming Examples
BMI Calculator in Python – A Complete Step-By-Step Tutorial

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 Or Body Mass Index Infographic Chart
BMI Or Body Mass Index Infographic Chart

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

Sample Output1 BMI
Sample Output1 BMI
Sample Output2 BMI
Sample Output2 BMI

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:

  1. How to Calculate Dot Product in Python?
  2. 4 Methods to Calculate Square Root in Python
  3. How to Calculate Summary Statistics in Python?
  4. How to Compute Distance in Python? [ Easy Step-By-Step Guide ]

Isha Bansal
Isha Bansal

Hey there stranger!
Do check out my blogs if you are a keen learner!

Hope you like them!

Articles: 185
Crypto Price Prediction with Python
Previous Post Crypto Price Prediction with Python
Next Post Animated Histograms in Python - A Step-By-Step Implementation
Animated Histograms in Python – A Step-By-Step Implementation

Related Posts

How to Calculate Distance Between Two Points in Python

How to Calculate Distance Between Two Points in Python

  • November 26, 2026
CIFAR 10 Dataset: Load and Use in Python

CIFAR 10 Dataset: Load and Use in Python

  • November 24, 2026
Maximum A Posteriori Estimation in Python

Maximum A Posteriori Estimation in Python

  • November 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.