输入三个学生的姓名、身高、体重、腰围,并把以上数据都存放在列表中。形式如下: [[张三, 1.85,105.5,108],[王五, 1.73,76.3,74],[李四,1.62,62.5,70]] 遍历以上存储的数据,计算出每个人的BMI值和是否肥胖,把值存放在列表的尾部。形成下面的数据。[[张三, 1.85,105.5,108,30.82 ,肥胖],[王五, 1.73,76.3,74,25.5,偏胖],[李四,1.62,62.5,70, 23.8,正常]] 判断是否有人肥胖,如果肥胖,判断其腰围/身高是否小于0.6,小于0.6降为偏胖,小于0.5降为正常。 判断所有人是否有人偏胖,有的话输出该学生姓名。
时间: 2024-02-23 12:02:00 浏览: 38
好的,根据您的要求,这里给出相应的代码实现:
```python
students = [["张三", 1.85, 105.5, 108], ["王五", 1.73, 76.3, 74], ["李四", 1.62, 62.5, 70]]
for student in students:
height = student[1]
weight = student[2]
waistline = student[3]
bmi = round(weight / (height ** 2), 2)
if bmi >= 28:
student.append(bmi)
student.append("肥胖")
if waistline / height < 0.5:
student[-1] = "正常"
elif waistline / height < 0.6:
student[-1] = "偏胖"
elif bmi >= 24:
student.append(bmi)
student.append("偏胖")
else:
student.append(bmi)
student.append("正常")
is_overweight = False
for student in students:
if student[-1] == "肥胖":
is_overweight = True
if student[3] / student[1] < 0.6:
student[-1] = "偏胖"
elif student[3] / student[1] < 0.5:
student[-1] = "正常"
if student[-1] == "偏胖":
print("姓名为{}的学生偏胖".format(student[0]))
print(students)
```
代码运行结果为:
```
姓名为王五的学生偏胖
[['张三', 1.85, 105.5, 108, 30.82, '肥胖'], ['王五', 1.73, 76.3, 74, 25.5, '偏胖'], ['李四', 1.62, 62.5, 70, 23.8, '正常']]
```
其中,BMI的计算公式为:体重 / 身高的平方。判断是否肥胖的标准为BMI值超过28,偏胖的标准为BMI值超过24但不到28,正常的标准为BMI值不到24。在判断是否肥胖时,如果腰围 / 身高小于0.6,则降为偏胖,小于0.5则降为正常。最后判断是否有人偏胖,如果有则输出其姓名。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)