top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Writer's pictureAruna Nuwantha

BMI App using python


Body Mass Index (BMI) is a commonly used indicator that gives information about how healthy your body is. It is given as a ratio between your weight and height. There is a simple formula to calculate BMI.


The formula is,


According to the below code, firstly I create the function of BMI, which returns the BMI according to the given mass and height parameters. So After the main function, I get the user inputs and check the validation of those inputs, as well as give the proper output.


#3. Body Mass Index calculator #find the body mass index - def BMI(mass, height): return mass / (height ** 2) if __name__ == '__main__': try: #get the input from users mass = float(input("Enter your mass(kg): ")) height = float(input("Enter your height(m): ")) print("BMI : {}".format(BMI(mass, height))) except: print("Error: Please enter the number")




There are some test cases here,


if you are using proper values to your weight and height, it will give the correct answer as BMI.

otherwise, if you are not using numbers for your weight, it will give an error.

if you are not using numbers for your height, it will give an errors



2 comments

Recent Posts

See All

2 Comments


Data Insight
Data Insight
Oct 09, 2021

Do not embed screen shot of codes in your posts. Use any of the methods described in this article https://linktrest.io/EmbedCode

Like
Aruna Nuwantha
Aruna Nuwantha
Oct 09, 2021
Replying to

okay thank you


Like
bottom of page