y_or_n = input('是否退出程序(y/n)?') while y_or_n != 'y': height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]: ")) bmi = weight / pow(height, 2) print("BMI 数值为:{:.2f}".format(bmi)) who, nat = "", "" if bmi < 18.5: who, nat = "偏瘦", "偏瘦" elif 18.5 <= bmi < 24: who, nat = "正常", "正常" elif 24 <= bmi < 25: who, nat = "正常", "偏胖" elif 25 <= bmi < 28: who, nat = "偏胖", "偏胖" elif 28 <= bmi < 30: who, nat = "偏胖", "肥胖" else: who, nat = "肥胖", "肥胖" print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat)) y_or_n = input('是否退出程序(y/n)?') y_or_n = input('是否退出程序(y/n)?') while y_or_n != 'y': height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]: ")) bmi = weight / pow(height, 2) print("BMI 数值为:{:.2f}".format(bmi)) who, nat = "", "" if bmi < 18.5: who, nat = "偏瘦", "偏瘦" elif 18.5 <= bmi < 24: who, nat = "正常", "正常" elif 24 <= bmi < 25: who, nat = "正常", "偏胖" elif 25 <= bmi < 28: who, nat = "偏胖", "偏胖" elif 28 <= bmi < 30: who, nat = "偏胖", "肥胖" else: who, nat = "肥胖", "肥胖" print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat)) y_or_n = input('是否退出程序(y/n)?')参照以上代码,写出类似的用于计算BMR的代码
时间: 2024-03-23 10:41:07 浏览: 41
BMI:应用程序根据用户的身高(m)和体重(Kg)计算其BMI并根据价值提出建议
Sure! 以下是一个类似的用于计算BMR的代码:
```python
y_or_n = input('是否退出程序(y/n)?')
while y_or_n != 'y':
gender = input("请输入性别(男/女):")
weight, height, age = eval(input("请输入体重(公斤)、身高(厘米)和年龄[逗号隔开]: "))
if gender == "男":
bmr = 13.7 * weight + 5.0 * height - 6.8 * age + 66
elif gender == "女":
bmr = 9.6 * weight + 1.8 * height - 4.7 * age + 655
else:
print("性别输入错误,请重新输入!")
continue
print("BMR 数值为:{:.2f}".format(bmr))
y_or_n = input('是否退出程序(y/n)?')
```
这个代码与之前的BMI计算代码类似,但是根据性别、体重、身高和年龄计算BMR。其中,男性的BMR计算公式为:13.7 × 体重(公斤) + 5.0 × 身高(厘米) - 6.8 × 年龄(岁) + 66;女性的BMR计算公式为:9.6 × 体重(公斤) + 1.8 × 身高(厘米) - 4.7 × 年龄(岁) + 655。
阅读全文