1234567891011121314151617181920212223242526272829303132333435 |
- """
- BMI指数计算
- ^^^^^^^^^^^
- 计算 `BMI指数 <https://en.wikipedia.org/wiki/Body_mass_index>`_ 的简单应用
- `Demo地址 <https://pywebio.herokuapp.com/?pywebio_api=bmi>`_ `源码 <https://github.com/wang0618/PyWebIO/blob/master/demos/bmi.py>`_
- """
- from pywebio import start_server
- from pywebio.input import *
- from pywebio.output import *
- def main():
- set_output_fixed_height(True)
- info = input_group('请输入', [
- input("请输入你的身高(cm)", name="height", type=FLOAT),
- input("请输入你的体重(kg)", name="weight", type=FLOAT),
- ])
- BMI = info['weight'] / (info['height'] / 100) ** 2
- top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),
- (22.9, '正常'), (27.5, '过重'),
- (40.0, '肥胖'), (float('inf'), '非常肥胖')]
- for top, status in top_status:
- if BMI <= top:
- put_markdown('你的 BMI 值: `%.1f`,身体状态:`%s`' % (BMI, status))
- break
- if __name__ == '__main__':
- start_server(main, debug=True, port=8080)
|