用户:
OTuTo查看:0 回复:1 评论:0 创建时间:2022-03-23T17:16:31
【作品展示】

【作品介绍】
这个BMI测试程序出现了错误,请大家帮忙改改
【作品源代码】
responses = {}
responseslist = 'E:\Python\作品\school_python_work\responseslist.txt'
nove = True
while nove:
#提示用户输入数据
name = input('你叫什么名字?')
weight = float(input(f'Hi!{name}你有多重?(kg)'))
hight = float(input('请问你有多高?(m)'))
#计算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}")
with open(responseslist, 'r') as ob:
ob.write(f"name:{name} BMI:{BMI}\n")
#储存数据到字典
responses[name] = BMI
#询问用户是否继续测试
question = input('请问你还要继续测试吗?(Yes/No)')
if question.lower() == 'no':
nove = False
print('------snip------')
print('--本次测试历史--')
for tname,tbmi in responses.items():
print(f"{nameB}'BMI is {BMIB}\n")
print("------历史记录------")
history = responseslist.read()
print(history)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn