|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
times=3
secret=random.randint(1,10)
guess=0
print('欢迎来到猜数字小游戏,本次小游戏数字范围为1到10,你只有三次机会猜出正确答案,否则就算游戏失败',end='')
while (guess !=secret) and (times >0):
temp =input()
secret =int(temp)
times =times-1
if guess==secret:
print('恭喜你猜中了正确数字')
else:
if guess>secret:
print('对不起,你输入的数字偏大')
else:
print('对不起,你输入的数字偏小')
if times>0:
print('输入错误,请再试一次',end='')
else:
print('对不起,你三次挑战机会已用完,游戏失败!')
print('游戏结束')
这是我编的一个小程序,初学者,但是打开后老是显示数字偏小,不管写多大的数字,求高手解答。
while (guess !=secret) and (times >0):
temp =input()
secret =int(temp)
times =times-1
input的数据应该给 guess,你这里给secret了
所以因为secret一致是0,所以除非输入0,不然都是偏小
|
|