231k views
5 votes
2-3 Calculating the Body Mass Index (BMI). (Programming Exercise 2.14) Body Mass Index is a measure of health based on your weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI. Note: One pound is 0.45359237 kilograms and one inch is 0.0254 meters. Hint: Convert the pounds entered into kilograms also convert the height in inches into meters Example: If you entered in pounds your weight as 95.5 and your height as 50 inches then the calculated BMI is 26.8573 FYI: BMI < 18.5 is underweight BMI >

1 Answer

4 votes

Answer:

weight = float(input("Enter your weight in pounds: "))

height = float(input("Enter your height in inches: "))

weight = weight * 0.45359237

height = height * 0.0254

bmi = weight / (height * height)

print("Your BMI is: %.4f" % bmi)

Step-by-step explanation:

*The code is written in Python.

Ask the user to enter weight in pounds and height in inches

Convert the weight into kilograms and height into meters using given conversion rates

Calculate the BMI using given formula

Print the BMI

User Frank Wang
by
4.7k points