用户:
OTuTo查看:0 回复:0 评论:0 创建时间:2023-05-21T21:43:01
【作品展示】

【作品介绍】
可以进行BMI值的测算与储存(需保存在本地并在同一文件下创建responseslist.txt)
【作品源代码】
import time
now = time.strftime("%Y-%m-%d %H:%M:%S")
responses = {}
responseslist = 'responseslist.txt'
with open(responseslist, 'a') as t:
while True:
#提示用户输入数据
name = str(input('你叫什么名字?'))
weight = float(input(f'Hi!{name}你有多重?(kg)'))
hight = float(input('请问你有多高?(m)'))
if weight == None or hight == None:
print("请输入数据!")
#计算BMI值
BMI = weight/hight**2
if BMI <18.5:
massage = '偏瘦'
if BMI >= 18.5 and BMI <24.9:
massage = '正常'
if BMI >=24.9 and BMI < 29.9:
massage = '偏胖'
if BMI >= 29.9:
massage = '肥胖'
#输出BMI值,并提示用户
print(f"你的BMI值是{BMI},{massage}")
#储存数据到字典
responses[name] = BMI
#储存数据到文件
t.write(f"时间:{now}\n")
t.write(f"名称:{name} BMI值:{BMI} 标准:{massage}\n")
#询问用户是否继续测试
question = input('请问你还要继续测试吗?(Yes/No)')
if question.lower() == 'no':
break
print('------snip------')
print('--本次测试历史--')
for tname,tbmi in responses.items():
print(f"{tname}'BMI is {tbmi}\n")
print("------历史记录------")
# history =str(responseslist.read())y.read()
with open(responseslist, 'r') as history:
hy = history.read()
print(hy)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn