Stop an Infinite Loop in Python While Statement -
Stop an Infinite Loop in Python While Statement -
i'm working on simple python programme involves creating circle "button" , having user click within circle. if don't click on circle, message comes stating have clicked outside of circle , should seek again. however, on lastly part i'm getting endless loop on code, despite using break. there way help see if there error? thanks!
r = 75 while true: # determine if click within circle length = math.sqrt(((x-100)**2) +((y-250)**2)) if length == r or length < r: break # prints if user not click within range print("please click within spin button")
x
, y
never updated within while
loop, if outside of circle in first iteration, length
remain @ same value (bigger r
), , break
statement never executed.
also, utilize if length >= r:
. no need check 2 conditions separately. (logically, should if length > r:
anyway since click on border of circle should still count.)
python python-3.x while-loop conditional-statements
Comments
Post a Comment