试图完成python家庭作业任务,该程序的一部分需要计算其计算出的BMI数以及用户写入“ n”后这些BMI的平均值。帮助将不胜感激,这就是我现在所拥有的。
y = True
while y:
weight = float(input("Enter weight in kg:"))
height = float(input("Enter height in m:"))
bmi = weight/(height**2)
if bmi <18:
print("Your BMI is", bmi, "\nIt indicates you are underweight")
elif bmi >=18 and bmi <=25:
print("Your BMI is", bmi, "\nIt indicates you are within normal bounds")
elif bmi >25:
print("Your BMI is", bmi, "\nIt indicates you are overweight")
again = str(input("Another BMI? y/n:"))
if again == "n":
y = False
答案 0 :(得分:0)
进入bmi_records
循环之前,您需要创建一个空列表while
。然后只需将新的BMI附加到bmi_records
列表中即可。
bmi_records = []
while ....
bmi = ...
bmi_records.append(bmi)
....
print(f'Average of {len(bmi_records)} BMIs entered: {sum(bmi_records)/len(bmi_records):.1f}')