top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Body Mass Index Calculator using Python

Writer's picture: Aldwin Dave ConahapAldwin Dave Conahap

This blog post describes a program that calculates body mass index(BMI). It classifies your weight status whether it is underweight, normal weight, overweight, or obese. Knowing your BMI is important as it may indicate any possible health risk, and implies immediate control, if needed. The following table shows the BMI ranges and their classifications:



Step 1: Generate a code that asks users to input their weight and height.

#For weight
try:
    weight = float(input("\nEnter your weight (in kg): "))
except ValueError:
    print("\nInvalid Input! Please input a number.")
    weight = float(input("\nEnter your weight (in kg): ")) 

#For height
try:
    height = float(input("\nEnter your height (in m): "))    
except ValueError:
    print("\nInvalid Input! Please input a number.")
    height = float(input("\nEnter your height (in m): ")) 

The code above allows users to input the necessary information in order for the program to perform the calculation. It also restricts invalid inputs and lets users try inputting a valid input again.


Step 2: Define the formula of the BMI.

BMI = weight / (height**2)

Step 3: Print the result.

print("Your BMI is "+str(round(BMI,3)))

It displays the user's BMI. The program rounded it to three decimal places for an easier read.


Step 4: After getting the result, create conditions that classify the status.

if BMI < 18.5:
    print("Status: Underweight")
elif BMI >= 18.5 and BMI < 25:
    print("Status: Normal weight")
elif BMI >= 25 and BMI < 30:
    print("Status: Overweight")
else: 
    print("Status: Obese")

Then, the weight status of the user will display.



 
 

1 Comment


Data Insight
Data Insight
Sep 19, 2021

Good expiation but didn't give any example using the code.

Like

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page