1
0

bmi.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. BMI指数计算
  3. ^^^^^^^^^^^
  4. 计算 `BMI指数 <https://en.wikipedia.org/wiki/Body_mass_index>`_ 的简单应用
  5. :demo_host:`Demo地址 </?pywebio_api=bmi>` `源码 <https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py>`_
  6. """
  7. from pywebio import start_server
  8. from pywebio.input import *
  9. from pywebio.output import *
  10. from pywebio.session import set_env
  11. def main():
  12. set_env(title="BMI Calculation")
  13. put_markdown("""# BMI指数
  14. [`BMI指数`](https://baike.baidu.com/item/%E4%BD%93%E8%B4%A8%E6%8C%87%E6%95%B0/1455733)(Body Mass Index,BMI),是用体重千克数除以身高米数的平方得出的数字,是国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。
  15. 成年人的BMI值处于以下阶段
  16. | 体形分类 | BMI值范围 |
  17. | -------- | --------- |
  18. | 极瘦 | BMI<14.9 |
  19. | 偏瘦 | 14.9≤BMI<18.4 |
  20. | 正常 | 18.4≤BMI<22.9 |
  21. | 过重 | 22.9≤BMI<27.5 |
  22. | 肥胖 | 27.5≤BMI<40 |
  23. | 非常肥胖 | BMI≥40 |
  24. ## BMI指数计算器
  25. 本程序的源代码[链接](https://github.com/wang0618/PyWebIO/blob/dev/demos/bmi.py)
  26. """, strip_indent=4)
  27. info = input_group('计算BMI:', [
  28. input("请输入你的身高(cm)", name="height", type=FLOAT),
  29. input("请输入你的体重(kg)", name="weight", type=FLOAT),
  30. ])
  31. BMI = info['weight'] / (info['height'] / 100) ** 2
  32. top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),
  33. (22.9, '正常'), (27.5, '过重'),
  34. (40.0, '肥胖'), (float('inf'), '非常肥胖')]
  35. for top, status in top_status:
  36. if BMI <= top:
  37. put_markdown('你的 BMI 值: `%.1f`,身体状态:`%s`' % (BMI, status))
  38. break
  39. if __name__ == '__main__':
  40. start_server(main, debug=True, port=8080)