Write a BMI calculator program using loop control, user-defined functions include list, arithmetic and decision control statements with the following conditions :
1) Prompt user to enter the weight in kilogram and height in metres up to 2 decimal places
2) Use the given formula to calculate the Body Mass Index (BMI) and round it to 2 decimal place
BMI = Weight / Height?
3) Create two data list namely, "name list" to store the username and the "bmi list" to store the calculated BMI respectively.
4) With the given BMI category, the program code is able to display the following:
a) Allow user to enter name, weight and height.
b) The username, the BMI value and the category that it falls into.
c) The usernames in the name list and the respective BMI values in the bmi_list.
BMI category are as follows
Less than 18.5
Underweight
18.5 to 24.9
Normal
25 to 29.9
Overweight
30 to 34.9
Obese class
35 to 39.9
Obese class Il
40 to 49.9
Morbid Obese
50 or greater
Obese class IlI
name_list=[]
bmi_list=[]
Wt=[]
Ht=[]
Category=[]
NO_OF_PERSONS=3
for r in range(0,NO_OF_PERSONS):
print("\nPerson-",r+1,"Data Entry:")
n = str (input("Enter name of the person: "))
name_list.append(n)
w = float(input("Enter weight in Kgs. : "))
Wt.append(w)
h = float(input("Enter height in meters : "))
Ht.append(h)
bmi = Wt[r]/Ht[r]
bmi_list.append(round(bmi,2))
if(bmi_list[r]<18.5): Category.append("Underweight")
if(bmi_list[r]>=18.5 and bmi_list[r]<25): Category.append("Normal")
if(bmi_list[r]>=25 and bmi_list[r]<30): Category.append("Overweight")
if(bmi_list[r]>=30 and bmi_list[r]<35): Category.append("Obese Class")
if(bmi_list[r]>=35 and bmi_list[r]<40): Category.append("Obsese Class II")
if(bmi_list[r]>=40 and bmi_list[r]<50): Category.append("Morbid Obses")
if(bmi_list[r]>50): Category.append("Obese Class III")
for r in range(0,NO_OF_PERSONS):
print("Name: %10s\tWt.: %3.2f Kgs.\tHeight: %2.2f meters\tBMI: %4.2f\tClass: %s"%(name_list[r],Wt[r],Ht[r],bmi_list[r],Category[r]))
Comments
Leave a comment