编写程序,根据身高和体重计算BMI值,同时输出国际和国内BMI指标建议值所确定的指标分类信息
时间: 2024-09-22 12:09:24 浏览: 41
编写一个计算BMI(身体质量指数)并根据标准分类的简单程序可以按照以下步骤进行。这里以Python为例:
```python
def calculate_bmi(height_cm, weight_kg):
height_m = height_cm / 100.0 # 转换为米
bmi = weight_kg / (height_m ** 2)
return bmi
def classify_bmi(bmi):
if bmi < 18.5:
category = "过轻"
elif 18.5 <= bmi < 24:
category = "正常"
elif 24 <= bmi < 28:
category = "超重"
else:
category = "肥胖"
return bmi, category
# 输入身高和体重
height_cm = float(input("请输入您的身高(厘米):"))
weight_kg = float(input("请输入您的体重(千克):"))
# 计算BMI
bmi = calculate_bmi(height_cm, weight_kg)
# 分类
international_classification = classify_bmi(bmi)
# 输出结果
print(f"您的BMI值是: {bmi}")
print(f"国际分类: {'健康' if international_classification[1] == '正常' else international_classification[1]}")
print(f"国内分类(中国成年人参考): {'偏低' if international_classification[1] == '过轻' else international_classification[1]}")
阅读全文