Answer:
underweight = ideal = overweight = obese = 0
underweight_count = ideal_count = overweight_count = obese_count = 0
average = count = total = 0
sign = ""
while True:
if sign == 'Q':
break
else:
weight = float(input("Enter the weight for student " + str(count+1) + ": "))
height = float(input("Enter the height for student " + str(count+1) + ": "))
BMI = weight / (height * height)
if BMI < 18.5:
underweight += BMI
underweight_count += 1
elif 18.5 <= BMI < 25:
ideal += BMI
ideal_count += 1
elif 25 <= BMI < 30:
overweight += BMI
overweight_count += 1
elif BMI >= 30:
obese += BMI
obese_count += 1
count += 1
sign = input("Press any key to continue, Q to quit")
total = underweight + ideal + overweight + obese
average = total / count
print("The number of underweight students: " + str(underweight_count))
print("The number of ideal students: " + str(ideal_count))
print("The number of overweight students: " + str(overweight_count))
print("The number of obese students: " + str(obese_count))
print("The average BMI is: " + str(average))
Explanation:
Inside the while loop:
- sign variable is used to ask the user to continue or stop
- If the user enters "Q" the loop terminates. Otherwise, it asks for the weight and height of the each student and calculates the BMI
- Depending the value of the BMI, number of the student in each category and their BMI is calculated
- When the loop is done, average BMI is calculated
- Required values are printed