当前位置:   article > 正文

Python实例9: BMI指数计算_python计算bmi

python计算bmi

方法一 

  1. name = str(input("请输入你的姓名:"))
  2. height = eval(input("请输入你的身高(m):"))
  3. weight = eval(input("请输入你的体重(kg):"))
  4. BMI = weight / pow(height, 2)
  5. print("BMI值为:{:.2f}".format(BMI)) # {:.2f} 调用方法保留小数点后两位
  6. if BMI < 18.5:
  7. print("偏瘦")
  8. else:
  9. if 18.5 < BMI < 25:
  10. print("正常")
  11. else:
  12. if 25 < BMI < 28:
  13. print("偏胖")
  14. else:
  15. if 28 < BMI < 32:
  16. print("肥胖")
  17. else:
  18. if BMI > 32:
  19. print("严重肥胖!")

方法二

  1. name = str(input("请输入你的姓名:"))
  2. height = eval(input("请输入你的身高(m):"))
  3. weight = eval(input("请输入你的体重(kg):"))
  4. BMI = weight / pow(height, 2)
  5. print("BMI值为:{:.2f}".format(BMI))
  6. if BMI < 18.5:
  7. print("偏瘦")
  8. elif 18.5 < BMI < 25:
  9. print("正常")
  10. elif 25 < BMI < 28:
  11. print("偏胖")
  12. elif 28 < BMI < 32:
  13. print("肥胖")
  14. else:
  15. print("严重肥胖!")

方法三

  1. # BMI指数计算
  2. height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]: "))
  3. bmi = weight / pow(height, 2)
  4. print("BMI 数值为:{:.2f}".format(bmi))
  5. who, nat = "", ""
  6. if bmi < 18.5:
  7. who, nat = "偏瘦", "偏瘦"
  8. elif 18.5 <= bmi < 24:
  9. who, nat = "正常", "正常"
  10. elif 24 <= bmi < 25:
  11. who, nat = "正常", "偏胖"
  12. elif 25 <= bmi < 28:
  13. who, nat = "偏胖", "偏胖"
  14. elif 28 <= bmi < 30:
  15. who, nat = "偏胖", "肥胖"
  16. else:
  17. who, nat = "肥胖", "肥胖"
  18. print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat))
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/389716?site
推荐阅读
相关标签
  

闽ICP备14008679号