0
我一直在研究對分數猜測遊戲,我想讓它自動工作,但代碼似乎陷入了循環。爲什麼循環永遠不會退出?
有什麼建議嗎?
x = 75
low = 0
high = 100
guessing = True
while guessing:
guess = int((high + low) // 2)
if guess == x:
guessing = False
elif guess < x:
high = guess
else:
low = guess
print("Your number is ", str(guess))
你應該通過你的算法「手工」,看看它是什麼。正如Kalpesh所說,你已經將「elif ... else」邏輯逆轉了。 –
現在我覺得啞巴了。感謝您的幫助 –