In: Computer Science
This involves writing a Python program to determine the
body-mass index of a collection of six individuals. Your program
should include a list of six names. Using a for loop, it should
successively prompt the user for the height in inches and weight in
pounds of each individual. Each prompt should include the name of
the individual whose height and weight is to be input. It should
call a function that accepts the height and weight as parameters
and returns the body mass index for that individual using the
formula weight × 703 / height2. That body mass index
should then be appended to an array. Using a second loop it should
traverse the array of body mass indices and call another function
that accepts the body mass index as a parameter and returns whether
the individual is underweight, normal weight or overweight. The
number of individuals in each category should be counted and the
number in each of those categories should be displayed. You should
decide on the names of the six individuals and the thresholds used
for categorization.
Your program should include the pseudocode used for your design in
the comments. Document the thresholds you chose for under weight
and over weight in your comments as well.
Code + Pseudocode + threshold used:
#function to calculate bmi
def bmi(h,w):
bmi=(w*703)/(h**2) #bmi formula
return bmi
#fumction to find category according to bmi
def bmi_category(bmi):
if bmi<18.5:
return 1
elif bmi>=18.5 and bmi<=24.9:
return 2
elif bmi>=25:
return 3
#main program
#list of names
li_name=["a","b","c","d","e","f"]
#list of bmi initialized
li_bmi=[0,0,0,0,0,0]
#calculating bmi from input of height and weight of each name
for i in range(6):
print("\nEnter height in inches of",li_name[i],": ",end="")
h=float(input())
print("\nEnter weight in pounds of",li_name[i],": ",end="")
w=float(input())
li_bmi[i]=bmi(h,w)
#initialize count for each category
count_underweight=0
count_normalweight=0
count_overweight=0
#initialize list of names under each category
li_under=[]
li_normal=[]
li_over=[]
#finding category of each bmi
for i in range(6):
x=bmi_category(li_bmi[i])
if x==1:
count_underweight = count_underweight + 1
li_under.append(li_name[i])
elif x==2:
count_normalweight = count_normalweight + 1
li_normal.append(li_name[i])
elif x==3:
count_overweight = count_overweight + 1
li_over.append(li_name[i])
#printing output
print("\n\nNumber of under weight persons =",count_underweight,"\n",li_under)
print("\n\nNumber of normal weight persons =",count_normalweight,"\n",li_normal)
print("\n\nNumber of over weight persons =",count_overweight,"\n",li_over)
#####################################################
#pseudocode
# 1. initialize name_list of 6.
# 2. initialize bmi_list of 6.
# 3.for each name in name_list, update corresponding bmi in bmi_list by taking its height and weight as input.
# 4.for each bmi in bmi_list find category of bmi according to threshold.
# 5.update count of bmi category and list of category with corresponding name.
# 6.print output as count and list of names for each category.
#threshold
# bmi categories:
# Under weight = <18.5
# Normal weight = 18.5–24.9
# Over weight = 25–29.9
OUTPUT: