交互式 Web 应用-PyWebIO
作者:互联网
参考
https://mp.weixin.qq.com/s/w4geqzmuqAXvE78257jQ2Q#
pip install pywebio
bmi.py
from pywebio import start_server
from pywebio.input import input, FLOAT
from pywebio.output import put_text
def bmi():
height = input("请输入你的身高(cm):", type=FLOAT)
weight = input("请输入你的体重(kg):", type=FLOAT)
BMI = weight / (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_text('你的 BMI 值: %.1f,身体状态:%s' % (BMI, status))
break
if __name__ == '__main__':
start_server(bmi, port=80)
webio_tornado.py
import tornado.ioloop
import tornado.web
from pywebio.platform.tornado import webio_handler
import bmi
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler),
(r"/bmi", webio_handler(bmi.bmi())), # bmi 即为上文计算BMI指数的函数
])
application.listen(port=80, address='localhost')
tornado.ioloop.IOLoop.current().start()
标签:__,Web,PyWebIO,tornado,bmi,pywebio,交互式,input,import 来源: https://blog.csdn.net/wuxingge/article/details/120882298