import random
number=random.randint(1,20)
print('guess a number between 1 to 20')
for a in range(1,7):
print('please guess')
try:
guess=int(input())
if guess>number:
print('too large')
elif guess<number:
print('too small')
else:
break
except ValueError:
print('you fool me!')
if guess==number:
print('yes,you get it in '+str(a)+' times')
else:
print('you are no change,the number is '+str(number))
以上为刚写的代码,问题是,如果我连续6次检测输入错误,就会向下继续执行代码,我的guess变量在try后面,识别不了。
number=random.randint(1,20)
print('guess a number between 1 to 20')
for a in range(1,7):
print('please guess')
try:
guess=int(input())
if guess>number:
print('too large')
elif guess<number:
print('too small')
else:
break
except ValueError:
print('you fool me!')
if guess==number:
print('yes,you get it in '+str(a)+' times')
else:
print('you are no change,the number is '+str(number))
以上为刚写的代码,问题是,如果我连续6次检测输入错误,就会向下继续执行代码,我的guess变量在try后面,识别不了。