而循环在Python中不起作用
while循环工作不正常。REACH变量将指示是否再次执行while循环。如果再次=1,则将执行while循环,程序将再次运行。如果再次=0,则它不会 由于某种原因,当循环始终被执行时,仍然始终=1,所以无论发生什么情况。有人注意到代码中有错误吗而循环在Python中不起作用,python,loops,while-loop,Python,Loops,While Loop,while循环工作不正常。REACH变量将指示是否再次执行while循环。如果再次=1,则将执行while循环,程序将再次运行。如果再次=0,则它不会 由于某种原因,当循环始终被执行时,仍然始终=1,所以无论发生什么情况。有人注意到代码中有错误吗 score = 0 loops = 0 again = 1 while (again != 0): import random real = random.randint(1,9) fake1 = random.rand
score = 0
loops = 0
again = 1
while (again != 0):
import random
real = random.randint(1,9)
fake1 = random.randint(1,9)
fake2 = random.randint(1,9)
comb = random.randint(1,9)
rep = 0
guess = 0
if (comb == 1 or comb == 2 or comb == 3):
print(real, fake1, fake2)
loops += 1
guess = int(input("Choose between these numbers"))
if (guess == real):
score += 1
print ("Congrats!")
else:
print ("Wrong, better luck next time!")
if (comb == 4 or comb == 5 or comb == 6):
print (fake1, fake2, real)
loops += 1
guess = int(input("Choose between these numbers"))
if (guess == real):
score += 1
print ("Congrats!")
else:
print ("Wrong, better luck next time!")
if (comb == 7 or comb == 8 or comb == 9):
print (fake2, real, fake1)
loops += 1
guess = int(input("Choose between these numbers"))
if (guess == real):
score += 1
print ("Congrats!")
else:
print ("Wrong, better luck next time!")
again == int(input("Do you wanna go again?"))
print(again)
这不会像您所想的那样,因为==意味着它正在检查此语句是否为真。你想要一个单人房= 将值赋给再次调用的变量时,使用比较运算符: 必须删除其中一个等号:
again = int(input("Do you wanna go again?"))
再一次==不是赋值,它是检查等式。哇,我不敢相信我没有看到这个。这么简单的修复!谢谢我觉得自己很笨,这么容易就搞定了。谢谢
again == int(input("Do you wanna go again?"))
again = int(input("Do you wanna go again?"))