我正在研究一个简单的python程序,它涉及到创建一个圆圈“按钮”,然后让用户在圆圈内单击。如果他们没有点击该圈子,则会显示一条消息,指出他们已经在圈子外点击并应该再试一次。但是,在最后一部分,尽管使用了中断,但我仍然在代码中获得了无限循环。有什么方法可以帮助人们查看是否有错误?谢谢!停止Python中的无限循环虽然语句
r = 75
while True:
# to determine if click is within circle
length = math.sqrt(((x-100)**2) +((y-250)**2))
if length == r or length < r:
break
# prints if user does not click within the range
print("Please click within the spin button")
当我使用长度的数值时,代码对我来说工作正常,看看您得到的x和y坐标是否正确以及您使用的公式。 – 2014-11-02 06:20:16