BMI (Body Mass Index) Calculator in Python

Python BMI Calculator Program: In this tutorial, we will learn how to design a BMI calculator using Python program? By Anoop Nair Last updated : April 13, 2023

What is Body Mass Index (BMI)?

The Body Mass Index (BMI) is a value used to define the ratio of a person's weight and height. Mathematically, BMI can be calculated as the body weight (in kg) divided by square of the person's height (in meters).

How to Calculate Body Mass Index (BMI)?

To calculate BMI, divide the weight (in kilogram) by height (in meters) squared. The formular is to calculate BMI is weight/(height2).

Logic to Calculate BMI (Body Mass Index) in Python

The following are the steps (logic) you should follow to implement a BMI calculator in Python:

  • We will first get input values from user using input() and convert it to float using float().
  • We will use the BMI formula, which is weight/(height**2).
  • Then print the result using conditional statements.
  • Here we have used elif because once we satisfy a condition we don't want to check the rest of the statements.

Example

Given weight and height of a person and we have to find the BMI (Body Mass Index) using Python.

Sample Input/Output

Input:
Height = 1.75
Weigth = 64

Output:
BMI is: 20.89 and you are: Healthy

Python Program to Implement BMI (Body Mass Index) Calculator

# getting input from the user and assigning it to user

height = float(input("Enter height in meters: "))
weight = float(input("Enter weight in kg: "))

# the formula for calculating bmi

bmi = weight/(height**2) 
# ** is the power of operator i.e height*height in this case

print("Your BMI is: {0} and you are: ".format(bmi), end='')

#conditions
if ( bmi < 16):
   print("severely underweight")

elif ( bmi >= 16 and bmi < 18.5):
   print("underweight")

elif ( bmi >= 18.5 and bmi < 25):
   print("Healthy")

elif ( bmi >= 25 and bmi < 30):
   print("overweight")

elif ( bmi >=30):
   print("severely overweight")

Output

Python program for BMI Calculator

If you liked the article or have any doubt, please write in the comment box.

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.