write a program (python) that asks the user to enter two values for weight and h
ID: 3734514 • Letter: W
Question
write a program(python) that asks the user to enter two values for weight and height respectively. The program checks whether the two entered values are valid. The value for weight should be between 100 and 400 pounds and the value for height should be between 48 and 84 inches. If any of the values are not valid, the program asks the user to try to re-enter two values. If, after three tries, one of the two entered values are valid, the program calculated BMI and displays a message:"Underweight"(if BMI<18.5); "Normal weight"(if 18.5 <= BMI <25); "Overweight"(if 25 <=BMI< 30); "Obesity"(if BMI>=30)
(weight in pounds is weight in pounds; height in inches is height in inches)
when I run the program, if I entered three times incorrect, it should be like this:
Enter weight in pounds: 500
Enter height in inches: 400
Enter weight in pounds: 500
Enter height in inches: 400
Enter weight in pounds: 600
Enter height in inches: 700
Invalid input.
Explanation / Answer
weightinpounds = input("Enter weight in pounds: ")
heightininches = input("Enter height in inches: ")
if weightinpounds <= 100 or weightinpounds >= 400:
weightinpounds = input("Enter weight in pounds: ")
if heightininches <= 48 or heightininches >= 84:
heightininches = input("Enter height in inches: ")
if weightinpounds <= 100 or weightinpounds >= 400:
weightinpounds = input("Enter weight in pounds: ")
if heightininches <= 48 or heightininches >= 84:
heightininches = input("Enter height in inches: ")
BMI = 703 * (weightinpounds)/(heightininches)^2
if weightinpounds >= 100 and weightinpounds <= 400 and heightininches >= 48 and heightininches <= 84:
if BMI <= 18.5:
print 'Your BMI is', BMI, 'Underweight'
elif BMI > 18.5 and BMI <= 25:
print 'Your BMI is', BMI, 'Normal'
elif BMI > 25 and BMI < 30:
print 'Your BMI is', BMI, 'Overweight'
else:
print 'Your BMI is', BMI, 'obesity'
else:
print 'Invalid input'
OUTPUT
Enter weight in pounds:
500
Enter height in inches:
400
Enter weight in pounds:
500
Enter height in inches:
400
Enter weight in pounds:
600
Enter height in inches:
700
Invalid input
OUTPUT
Enter weight in pounds:
200
Enter height in inches:
80
Your BMI is
1759
obesity
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.