[英]How would I count the number of people in each category BMI calculator
What do I need to do to count out each individual in each category.我需要做什么来计算每个类别中的每个人。 Underweight, normal weight, over weight and obese?
体重过轻、正常体重、超重和肥胖? The number of individuals in each category counted and the number in each of those categories displayed?
统计的每个类别中的个人数量以及显示的每个类别中的数量?
recipients = ["John", "Dee", "Aleister", "Lilith", "Paul", "Reggy"]
BMI_calc = []
def BMI(weights, heights):
bmi_total = (weights * 703) / (heights ** 2)
return bmi_total
def check(BMI):
if BMI <= 18.5:
print("Your underweight.")
elif BMI > 18.5 and BMI < 24.9:
print("You're normal weight.")
elif BMI > 25 and BMI < 29.9:
print("You're overweight.")
elif BMI > 30:
print("You're obese.")
for recipient in recipients:
heights_ = int(input("What is your height " + recipient + " :" ))
weights_ = int(input("What is your weight " + recipient + " :" ))
BMI_info={"name":recipient,"weight":weights_,"height":heights_,"BMI":BMI(weights_, heights_)}
BMI(BMI_info["weight"],BMI_info["height"])
BMI_calc.append(BMI_info)
for person_info in BMI_calc:
print(person_info["name"],end="\t")
check(person_info["BMI"])
overweight, underweight, normal, obese = 0
def check(BMI):
if BMI <= 18.5:
print("Your underweight.")
underweight += 1
elif BMI > 18.5 and BMI < 24.9:
print("You're normal weight.")
normal += 1
elif BMI > 25 and BMI < 29.9:
print("You're overweight.")
overweight +=1
elif BMI > 30:
print("You're obese.")
obese += 1
You can print or do anything you want to do with the count integer您可以使用计数 integer 打印或做任何您想做的事情
I was having the same issue as you which is how I came across your question(s).我遇到了和你一样的问题,这就是我遇到你的问题的方式。 Instead of counting the normal way (ex. underweight += 1), I created lists for each category of BMIs.
我没有按常规方式计算(例如体重不足 += 1),而是为每个 BMI 类别创建了列表。 I only used 3 categories
我只使用了 3 个类别
OVER_LIST = []
UNDER_LIST = []
NORMAL_LIST = []
my function looked like this:我的 function 看起来像这样:
def your_function_name():
if BMI > 30:
OVER_LIST.append(BMI)
elif BMI < 10:
UNDER_LIST.append(BMI)
else:
NORMAL_LIST.append(BMI)
finally I called the function with each iteration of the for loop and simply printed the length of the lists:最后,我在 for 循环的每次迭代中调用了 function 并简单地打印了列表的长度:
for BMI in BMI_list:
your_function_name()
print('Overweight = ',len(OVER_LIST),'\nUnderweight = ',len(UNDER_LIST),'\nNormal weight = ',len(NORMAL_LIST))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.