python bmi
时间: 2023-11-15 10:58:23 浏览: 101
BMI是身体质量指数(Body Mass Index)的缩写,是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。Python是一种高级编程语言,可以用来编写各种应用程序,包括计算BMI指数的程序。下面是两种不同的Python代码实现计算BMI指数和判断身体状态的方法:
方法一:
```
name = input('Name')
height = input('Height(m):')
weight = input('Weight(kg):')
BMI = float(float(weight)/(float(height)**2))
if BMI < 18.5:
print('过轻')
elif BMI <= 25:
print('正常')
elif BMI <= 28:
print('过重')
elif BMI <= 32:
print('肥胖')
else:
print('严重肥胖')
```
方法二:
```
height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]:"))
bmi = weight / pow(height , 2)
who , nat = " "," "
if bmi < 18.5:
who , nat = "偏瘦","偏瘦"
elif bmi >= 18.5 and bmi < 24:
who , nat = "正常","正常"
elif bmi >=24 and bmi <25:
who , nat = "正常","偏胖"
elif bmi >=25 and bmi <28:
who , nat = "偏胖","偏胖"
elif bmi >=28 and bmi <30:
who , nat = "偏胖","肥胖"
elif bmi >=30:
who , nat = "肥胖","肥胖"
print("BMI指标为: 国际{0},国内{1}".format(who,nat))
```
阅读全文