61.5k views
4 votes
Draw the hierarchy chart and then plan the logic for a program that calculates a person's body mass index (BMI). BMI is a statistical measure that compares a person's weight and height. The program uses three modules. The first prompts a user for and accepts the user's height in inches. The second module accepts the user's weight in pounds and converts the user's height to meters and weight to kilograms. Then, it calculates BMI as weight in kilograms divided by height in meters squared, and displays the results. There are 2.54 centimeters in an inch, 100 centimeters in a meter, 453.59 grams in a pound, and 1,000 grams in a kilogram. Use named constants whenever you think they are appropriate. The last module displays the message End of job.

1 Answer

6 votes

Step-by-step explanation:

First, user is asked to input height in inches and weight in pounds.

Secondly, conversion of pounds into kgs is done using the ratios given in the problem.

Thirdly, BMI is calculated using the formula weight in kg's divided by height in meters squared then rounding to the first decimal point and displaying.

Lastly, cases of under-weight, normal weight and over-weight are determined according to the BMI.

Python Code:

h=int(input("Please enter your height in inches: "))

w=int(input("Please enter your weight in pounds: "))

height = h*2.54/100

weight = w*453.59/1000

BMI = weight/(height*height)

print("your BMI is: ", round(BMI,1))

if BMI <= 18.5:

print("You are under-weight! eat more")

elif BMI >18.5 and BMI <= 24.9:

print("You are normal-weight!")

else:

print("You are over-weight! eat less")

Output:

Please enter your height in inches: 68

Please enter your weight in pounds: 150

your BMI is: 22.8

You are normal-weight!

Please enter your height in inches: 70

Please enter your weight in pounds: 250

your BMI is: 35.9

You are over-weight! eat less

User Albertina
by
5.1k points