|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#p3_85.py
import easygui as eg
try:
成绩 = int(eg.enterbox(msg = '请输入成绩:' , title = '成绩评价系统'))
if 成绩 < 0.25 or 成绩 > 120.25 or 成绩 == None:
成绩 = eg.enterbox(msg = '输入错误!请重新输入成绩:' , title = '成绩评价系统')
elif 成绩 == 120:
eg.msgbox(msg = '评价等级:SSS' , title = '结果' , ok_button = '确定')
elif 成绩 > 115:
eg.msgbox(msg = '评价等级:SS' , title = '结果' , ok_button = '确定')
elif 成绩 > 110:
eg.msgbox(msg = '评价等级:S' , title = '结果' , ok_button = '确定')
elif 成绩 > 95:
eg.msgbox(msg = '评价等级:A+' , title = '结果' , ok_button = '确定')
elif 成绩 > 80:
eg.msgbox(msg = '评价等级:B' , title = '结果' , ok_button = '确定')
elif 成绩 > 75:
eg.msgbox(msg = '评价等级:C-' , title = '结果' , ok_button = '确定')
elif 成绩 < 75:
eg.msgbox(msg = '评价等级:D' , title = '结果' , ok_button = '确定')
except (ValueError , TypeError) as tc:
eg.msgbox(msg = ('出错啦!T_T/n错误原因是:' + tc) , title = '错误' , ok_button = '确定')
为啥运行之后不输入报错?
本帖最后由 isdkz 于 2022-5-5 22:47 编辑
这个是在 except 里面出错的,因为异常类不是字符串,
不能直接跟字符串拼接,所以需要用 str() 转化成字符串
#p3_85.py
import easygui as eg
try:
成绩 = int(eg.enterbox(msg = '请输入成绩:' , title = '成绩评价系统'))
if 成绩 < 0.25 or 成绩 > 120.25 or 成绩 == None:
成绩 = eg.enterbox(msg = '输入错误!请重新输入成绩:' , title = '成绩评价系统')
elif 成绩 == 120:
eg.msgbox(msg = '评价等级:SSS' , title = '结果' , ok_button = '确定')
elif 成绩 > 115:
eg.msgbox(msg = '评价等级:SS' , title = '结果' , ok_button = '确定')
elif 成绩 > 110:
eg.msgbox(msg = '评价等级:S' , title = '结果' , ok_button = '确定')
elif 成绩 > 95:
eg.msgbox(msg = '评价等级:A+' , title = '结果' , ok_button = '确定')
elif 成绩 > 80:
eg.msgbox(msg = '评价等级:B' , title = '结果' , ok_button = '确定')
elif 成绩 > 75:
eg.msgbox(msg = '评价等级:C-' , title = '结果' , ok_button = '确定')
elif 成绩 < 75:
eg.msgbox(msg = '评价等级:D' , title = '结果' , ok_button = '确定')
except (ValueError , TypeError) as tc:
eg.msgbox(msg = ('出错啦!T_T/n错误原因是:' + str(tc)) , title = '错误' , ok_button = '确定') # tc 改成 str(tc)
|
|