【发布时间】:2021-02-11 23:54:07
【问题描述】:
以下等式估算运动时燃烧的卡路里(来源):
男士:Calories = [(Age x 0.2017) — (Weight x 0.09036) + (Heart Rate x 0.6309) — 55.0969] x Time / 4.184
女性:Calories = [(Age x 0.074) — (Weight x 0.05741) + (Heart Rate x 0.4472) — 20.4022] x Time / 4.184
使用输入年龄(岁)、体重(磅)、心率(每分钟跳动次数)和时间(分钟)编写程序。输出男性和女性燃烧的卡路里。
例如:如果输入是:
49
155
148
60
那么输出是:
Men: 489.7772466539196 calories
Women: 580.939531548757 calories
我的代码 -
age_years = float(input('Enter your age in years:\n'))
weight_lbs = float(input('Enter your weight in pounds:\n'))
heart_rate = float(input('Enter your heart rate in beats per minute:\n'))
time_min = float(input('Enter total time in minutes:\n'))
men_calories = [(age_years * 0.2017) - (weight_lbs * 0.09036) + (heart_rate * 0.6309) - 55.0969] * (time_min / 4.184)
women_calories = [(age_years * 0.074) - (weight_lbs * 0.05741) + (heart_rate * 0.4472) - 20.4022] * (time_min / 4.184)
print("Men:" , men_calories)
Error: Traceback (most recent call last):
File "main.py", line 8, in <module>
men_calories = [(age_years * 0.2017) - (weight_lbs * 0.09036) + (heart_rate * 0.6309) - 55.0969] * (time_min / 4.184)
TypeError: can't multiply sequence by non-int of type 'float'
我在这里做错了什么?
【问题讨论】: