bmi.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. BMI指数计算
  3. ^^^^^^^^^^^
  4. 计算 `BMI指数 <https://en.wikipedia.org/wiki/Body_mass_index>`_ 的简单应用
  5. `Demo地址 <https://pywebio.herokuapp.com/?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. info = input_group('请输入', [
  13. input("请输入你的身高(cm)", name="height", type=FLOAT),
  14. input("请输入你的体重(kg)", name="weight", type=FLOAT),
  15. ])
  16. BMI = info['weight'] / (info['height'] / 100) ** 2
  17. top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),
  18. (22.9, '正常'), (27.5, '过重'),
  19. (40.0, '肥胖'), (float('inf'), '非常肥胖')]
  20. for top, status in top_status:
  21. if BMI <= top:
  22. put_markdown('你的 BMI 值: `%.1f`,身体状态:`%s`' % (BMI, status))
  23. break
  24. if __name__ == '__main__':
  25. start_server(main, debug=True, port=8080)