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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -