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”逻辑逆转了。 –
现在我觉得哑巴了。感谢您的帮助 –