bmi.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/master/demos/bmi.py>`_
  6. """
  7. from pywebio import start_server
  8. from pywebio.input import *
  9. from pywebio.output import *
  10. def main():
  11. set_output_fixed_height(True)
  12. set_title("BMI Calculation")
  13. put_markdown("""计算 [`BMI指数`](https://baike.baidu.com/item/%E4%BD%93%E8%B4%A8%E6%8C%87%E6%95%B0/1455733) 的简单应用,源代码[链接](https://github.com/wang0618/PyWebIO/blob/master/demos/bmi.py)""", lstrip=True)
  14. info = input_group('请输入', [
  15. input("请输入你的身高(cm)", name="height", type=FLOAT),
  16. input("请输入你的体重(kg)", name="weight", type=FLOAT),
  17. ])
  18. BMI = info['weight'] / (info['height'] / 100) ** 2
  19. top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),
  20. (22.9, '正常'), (27.5, '过重'),
  21. (40.0, '肥胖'), (float('inf'), '非常肥胖')]
  22. for top, status in top_status:
  23. if BMI <= top:
  24. put_markdown('你的 BMI 值: `%.1f`,身体状态:`%s`' % (BMI, status))
  25. break
  26. if __name__ == '__main__':
  27. start_server(main, debug=True, port=8080)