w3resource

Python: Calculate body mass index

Python Basic: Exercise-66 with Solution

Write a Python program to calculate the body mass index.

Pictorial Presentation:

Calculate body mass index

Sample Solution:

Python Code:

# Prompt the user to input their height in feet and convert it to a floating-point number.
height = float(input("Input your height in Feet: "))

# Prompt the user to input their weight in kilograms and convert it to a floating-point number.
weight = float(input("Input your weight in Kilograms: "))

# Calculate the body mass index (BMI) using the provided height and weight and round it to 2 decimal places.
bmi = weight / (height * height)
rounded_bmi = round(bmi, 2)

# Print the calculated BMI.
print("Your body mass index is: ", rounded_bmi)

Sample Output:

Input your height in Feet:  6
Input your weight in Kilogram:  65
Your body mass index is:  1.81

Flowchart:

Flowchart: Calculate body mass index.

Python Code Editor:

 

Previous: Write a Python program to convert seconds to day, hour, minutes and seconds.
Next: Write a Python program to convert pressure in kilopascals to pounds per square inch,a millimeter of mercury (mmHg) and atmosphere pressure.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.