In: Computer Science
Develop a Python program to identify the body-mass index of a collection of six individuals. Your program should include a list of six names. Note: If you chose to prompt for the names, build the list of names first, then do the following prompt for height, weight. 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 display the name of the individual whose height and weight is to be input. Your program should validate that input for height and weight are positive. 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: BMindex = weight × 703 / height2. (eg. 200lb, 6ft(72in) would be: BMindex = (200*703)/(72*72) = 27.1219 ). That body mass index should then be appended to a 2nd "parallel" 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 at least six individuals and the thresholds used for categorization. Note: two loops and at least two functions. Display your name,class,date as per SubmissionRequirements by using a function.
code:
#function to caluclate BMindex
def bodymass_Index(hw):
BMindex=[]
#caluclating using given formula
for i in hw:
BMindex.append(i[1]*703/(i[0]*i[0]))
return BMindex
#counting categories members
def caluclate(BMindex):
underwieght=0
normalwieght=0
overwieght=0
for i in BMindex:
if i<18.5:
underwieght=underwieght+1
elif i>=18.5 and i<=24.9:
normalwieght=normalwieght+1
elif i>=25:
overwieght=overwieght+1
print("underwieght :",underwieght)
print("normalwieght :",normalwieght)
print("overwieght :",overwieght)
#list for names you can modify the names
names=['tony','captain','thor','banner','natasha','peter']
hw=[]
print("Please input hight in Inches and wieght in Pounds :")
#input
for i in names:
h,w=-1,-1
#validating nagative input
while h<0 or w<0:
h,w=map(int,input("{} :".format(i)).split())
if h<0 or w<0:
print("invalid data ! please re enter")
continue
hw.append([h,w])
BMindex=bodymass_Index(hw)
caluclate(BMindex)
sample testing:
If you have any doubt please leave a comment.
please upvote.