大佬们提个建议呗~
#p4_4.pyimport easygui as eg
import random as rdm
try:
eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
答案 = rdm.randint(1,1000)
回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-1000):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 1000)
次数 = 1
while 回答!= 答案 and 次数 <= 20:
if 回答 == None:
eg.msgbox(msg = '输入不能为空!' , title = '请重来!' , ok_button = '重来')
continue
if 回答 > 答案:
回答 = eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 1000)
次数 += 1
if 回答 < 答案:
回答 = eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 1000)
次数 += 1
if 回答 == 答案:
eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
except ValueError as cut:
eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
请大佬们提个建议^_^ 不要用中文当变量名 #p4_4.py
import easygui as eg
import random as rdm
try:
eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
答案 = rdm.randint(1,1000)
回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-1000):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 1000)
次数 = 1
while 回答!= 答案 and 次数 <= 20:
if 回答 == None:
eg.msgbox(msg = '输入不能为空!' , title = '请重来!' , ok_button = '重来')
continue
if 回答 > 答案:
回答 = eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 1000)
次数 += 1
if 回答 < 答案:
回答 = eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 1000)
次数 += 1
if 回答 == 答案:
eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
except ValueError as cut:
eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')为啥不能?运行也没有问题呀~ 规范问题 小凯2013 发表于 2022-5-3 21:23
为啥不能?运行也没有问题呀~
你可以去搜一下变量命名规则。 虽然python3是支持中文变量名的,但是其他编程语言就不行,python2也不行,而用中文取名也有许多劣势,在小甲鱼的课后作业里也会讲 其他先不说,先提一点,尽量不要用中文名作为变量名
页:
[1]