简体   繁体   English

我将如何计算每个类别 BMI 计算器中的人数

[英]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.

相关问题 您如何创建一个 function 来接收类别列表并计算每个类别中的元素数量? - How do you create a function that would take in a list of categories and count the number of elements in each category? 如何在此计算器中调用身高体重和 bmi? - How do I make height weight and bmi able to be called in this calculator? 我如何编写代码来处理 BMI 计算器的输入错误? - How do i write code to handle Input error with BMI calculator? 提供BMI值时,如何阻止BMI计算器添加不需要的“无”? - How do I stop my BMI calculator from adding an unwanted “None” when giving the BMI value? 如何修复此Python BMI计算器? - How to fix this Python BMI calculator? 如何在pydatadable中使用group by计算每个类别的实例数 - How to count the number of instances for each category using group by in pydatadable bmi 计算器如何重新启动计算器到 go 回到顶部的是/否 - bmi calculator how do restart the calculator to go back to yes/no at the top 如何从 twilio 号码拨打电话到任何其他号码,这将有助于两个人互相交谈的服务 - how to make a phone call from twilio number to any other number which would facilitate the service of two people talking to each other 没有重复,计算每天进入的人数 - Without duplication, count number of people entering each day 我如何为玩家计算每副套牌中的 A? - How would I count the aces in each of the decks for the players?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM