赞
踩
方法一
- name = str(input("请输入你的姓名:"))
- height = eval(input("请输入你的身高(m):"))
- weight = eval(input("请输入你的体重(kg):"))
-
- BMI = weight / pow(height, 2)
- print("BMI值为:{:.2f}".format(BMI)) # {:.2f} 调用方法保留小数点后两位
- if BMI < 18.5:
- print("偏瘦")
- else:
- if 18.5 < BMI < 25:
- print("正常")
- else:
- if 25 < BMI < 28:
- print("偏胖")
- else:
- if 28 < BMI < 32:
- print("肥胖")
- else:
- if BMI > 32:
- print("严重肥胖!")
方法二
- name = str(input("请输入你的姓名:"))
- height = eval(input("请输入你的身高(m):"))
- weight = eval(input("请输入你的体重(kg):"))
-
- BMI = weight / pow(height, 2)
- print("BMI值为:{:.2f}".format(BMI))
- if BMI < 18.5:
- print("偏瘦")
- elif 18.5 < BMI < 25:
- print("正常")
- elif 25 < BMI < 28:
- print("偏胖")
- elif 28 < BMI < 32:
- print("肥胖")
- else:
- print("严重肥胖!")
方法三
- # BMI指数计算
- 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))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。