g A fitness instructor wants to find out the number of students who are underweight, ideal, overweight and obese. The BMI (Body Mass Index) is a common tool for deciding whether a person has an appropriate body weight. It measures a person's weight in relation to their height. You have been asked to create a program to calculate BMI of each student, determine number of students in each category and an average BMI. BMI is calculated as follows: BMI = (weight)/(height*height). BMI Category Less than 18.5 Underweight At least 18.5 but less than 25 Ideal At least 25 but less than 30 Overweight Over 30 Obese Your goal is to create an application to allow the fitness instructor to continuously input height (meters) and weight (kilograms) until the fitness instructor has indicated they are finished entering data. When an invalid input is provided the user must see an error message and be re prompted. Once all of the data has been entered, generate a report showing the number of students in each category and the average BMI.

Respuesta :

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

ACCESS MORE
EDU ACCESS