SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:6 | ISBN:978013274719 | Edition: 6

Question

(Health application: BMI ) Revise Listing 4.6, ComputeBMI.py, to let users enter their weight in pounds and their height in feet and inches. For example, if a person is 5 feet and 10 inches, you will enter 5 for feet and 10 for inches. Here is a sample run:

Enter weight in pounds: 140
Enter feet: 5
Enter inches: 10
BMI is 20.087702275404553
You are Normal
 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

SOURCE CODE
# Prompt the user to enter weight in pounds
weight = eval(input("Enter weight in pounds: "))
# Prompt the user to enter weight in feets
feets = eval(input("Enter feet: "))
# Converting feets into inches
a = feets * 12
# Prompt the user to enter height in inches
inches = eval(input("Enter inches: "))
# total height
height = a + inches
KILOGRAMS_PER_POUND = 0.45359237
METERS_PER_INCH = 0.0254
# Compute BMI
weightInKilograms = weight * KILOGRAMS_PER_POUND  
heightInMeters = height * METERS_PER_INCH   
bmi = weightInKilograms / (heightInMeters * heightInMeters)
# Display result
print("BMI is", format(bmi, ".2f"))
if bmi < 18.5:
    print("You are Underweight")
elif bmi < 25:
    print("You areNormal")
elif bmi < 30:
    print("You are Overweight")
else:
    print("You are Obese")

OUTPUT
 Enter weight in pounds: 140
 Enter Feets: 5
 Enter inches: 10
 BMI is 20.09
 You are Normal

 

0 0

Discussions

Post the discussion to improve the above solution.