想要知道这些代码哪里出的问题,重复输入10 一会提示大了,一会提示小了。
import random
times = 3
x = random.randint(1,10)
print('---------猜数字小游戏---------')
temp= input('猜猜看现在是1-10之间的什么数字:')
guess = int(temp)
while guess != x and times > 0:
times -= 1
if guess > 10 or guess < 0 :
print('请输入规格内的数字。')
temp = input('请继续输入吧:')
guess = int(temp)
else:
if guess > x and times != 0:
print('呀,大啦!')
print('再想一下吧')
temp = input('请继续输入吧:')
guess = int(temp)
else:
print('嘿,小啦!')
print('真笨!')
temp = input('请重新输入吧:')
guess = int(temp)
while guess != x and times == 0:
print('次数用完咯。')
break
else:
print('猜对啦')
break
print ('好啦,不玩啦!')
if guess > x and times != 0:
因为你这边用了and,改成or 即可
import random
times = 3
x = random.randint(1,10)
print('---------猜数字小游戏---------')
temp= input('猜猜看现在是1-10之间的什么数字:')
guess = int(temp)
while guess != x and times > 0:
times -= 1
if guess > 10 or guess < 0 :
print('请输入规格内的数字。')
temp = input('请继续输入吧:')
guess = int(temp)
else:
if guess > x or times != 0:
print('呀,大啦!')
print('再想一下吧')
temp = input('请继续输入吧:')
guess = int(temp)
else:
print('嘿,小啦!')
print('真笨!')
temp = input('请重新输入吧:')
guess = int(temp)
while guess != x and times == 0:
print('次数用完咯。')
break
else:
print('猜对啦')
break
print ('好啦,不玩啦!') 请大佬指教orz ☆·再睡℡①夏 发表于 2020-6-11 21:13
请大佬指教orz
看楼上哈~ Twilight6 发表于 2020-6-11 21:12
因为你这边用了and,改成or 即可
thx {:5_106:} ☆·再睡℡①夏 发表于 2020-6-11 21:17
thx
记得给个最佳哈~ Twilight6 发表于 2020-6-11 21:12
因为你这边用了and,改成or 即可
我刚试了下,却是不会忽大忽小了,但是下面的while语句就没有作用了呢 Twilight6 发表于 2020-6-11 21:18
记得给个最佳哈~
嗯嗯,好的{:9_227:} ☆·再睡℡①夏 发表于 2020-6-11 21:24
我刚试了下,却是不会忽大忽小了,但是下面的while语句就没有作用了呢
OK我帮你看看代码哈~ Twilight6 发表于 2020-6-11 21:29
OK我帮你看看代码哈~
谢谢{:10_254:} 本帖最后由 Twilight6 于 2020-6-11 21:35 编辑
☆·再睡℡①夏 发表于 2020-6-11 21:30
谢谢
小小改动下~
import random
times = 3
x = random.randint(1,10)
print('---------猜数字小游戏---------')
temp= input('猜猜看现在是1-10之间的什么数字:')
guess = int(temp)
while guess != x and times > 0:
if guess > 10 or guess < 0 :
print('请输入规格内的数字。')
temp = input('请继续输入吧:')
guess = int(temp)
else:
times -= 1
if times == 0 and guess != x:
print('哎呀,还是错了!正确答案是:',x,'你的次数用完咯。')
break
if guess > x :
print('呀,大啦!')
print('再想一下吧')
temp = input('请继续输入吧:')
guess = int(temp)
else:
print('嘿,小啦!')
print('真笨!')
temp = input('请重新输入吧:')
guess = int(temp)
if guess == x:
print('恭喜你!答对啦~~')
print ('好啦,不玩啦!') Twilight6 发表于 2020-6-11 21:32
小小改动下~
膜拜大佬 orz {:10_257:} ☆·再睡℡①夏 发表于 2020-6-11 21:35
膜拜大佬 orz
重新复制代码哈 刚刚漏了一些 Twilight6 发表于 2020-6-11 21:36
重新复制代码哈 刚刚漏了一些
恩嗯,好的
页:
[1]