刚刚上到改进小游戏的萌新求助!
大佬们好!请大佬们看看我这串代码出现了什么问题?
为什么停不下来?
import random
times = 3
secret=random.randint(1,10)
print("Let's get start")
temp=input("Let's guess what i'm thinking right now:")
guess=int(temp)
while guess !=secret:
if guess >secret:
print("Smaller than it")
else:
if guess ==secret:
print("Ahh, cool, that's good")
else:
print("Bigger than it")
print("that's all, you won't have more chance") import random
times = 3
secret=random.randint(1,10)
print("Let's get start")
temp=input("Let's guess what i'm thinking right now:")
guess=int(temp)
if guess == secret:
print('Congratulations')
else:
while guess !=secret and times>0:
temp=input("Trt again:")
guess=int(temp)
times -= 1
if guess >secret:
print("Smaller than it")
else:
if guess ==secret:
print("Ahh, cool, that's good")
else:
print("Bigger than it")
print("that's all, you won't have more chance") while循环中没有修改guess的值,判断永远为真,所以死循环了 import random
times = 2
secret=random.randint(1,10)
print("Let's get start")
guess = int(input("Let's guess what i'm thinking right now:"))
while times:
guess = int(input("pleaese try again:"))
times -= 1
if guess == secret:
print("Ahh, cool, that's good")
break
else:
if guess > secret:
print("Bigger than it")
else:
print("Smaller than it")
print("that's all, you won't have more chance") x287208793 发表于 2019-7-10 16:09
感谢大佬! BngThea 发表于 2019-7-10 09:09
while循环中没有修改guess的值,判断永远为真,所以死循环了
原来是这样,感谢大佬!
页:
[1]