1.身体质量指数(Body Mass Index,BMI) 是国际上常用的衡量人 体肥胖程度和是否健康的重要标准,计算公式为:BMI = 体重/身高的平 方(国际单位kg/m2)。 定义BMI类
时间: 2024-12-17 14:46:19 浏览: 145
定义BMI类是一个简单的步骤,通常会在面向对象编程中创建。下面是一个基本的Python类示例,用于表示BMI并包含计算方法:
```python
class BMI:
def __init__(self, weight, height):
"""
初始化BMI类,输入体重(千克)和身高(米)
"""
self.weight = weight
self.height = height
def calculate_bmi(self):
"""
计算BMI值
"""
bmi = self.weight / (self.height ** 2)
return bmi
def get_classification(self, bmi_thresholds):
"""
根据BMI值返回相应的分类,如正常、偏胖、肥胖等
"""
if bmi_thresholds["underweight"] <= self.calculate_bmi() < bmi_thresholds["normal"]:
return "正常"
elif bmi_thresholds["normal"] <= self.calculate_bmi() < bmi_thresholds["overweight"]:
return "偏胖"
elif bmi_thresholds["overweight"] <= self.calculate_bmi():
return "肥胖"
else:
return "无法确定"
# 示例使用
bmi_thresholds = {"underweight": 18.5, "normal": 24.9, "overweight": 29.9}
my_bmi = BMI(70, 1.75) # 假设一个人的体重是70公斤,身高是1.75米
print(f"我的BMI是: {my_bmi.calculate_bmi()},属于: {my_bmi.get_classification(bmi_thresholds)}")
```
阅读全文
相关推荐

















