Lesson goal: The while-loop and mouse clicks

Previous: Average some numbers | Home | Next: You guess my number

Here's a use of the while-loop that waits (with a while loop) for you to click inside of the circle drawn on the screen. It computes the distance of your mouse click to the origin to see if you are inside of the circle of radius 20 pixels. Note the logic...setting the variable called done to false, to "prime" the while-loop. The while-loop executes over and over while the done variable is false.

Now you try. Fix the d= line to be the distance of your mouse click to the origin, and the if statement to see if this distance is $\le 20$ (the radius of the circle).

Type your code here:

See your results here:

This code will not run! What will you put inside of the math.sqrt(..) line that causes d to be assigned to the distance of your $(x,y)$ mouse click to the origin? Next, what condition will you put in the if statement that will execute the done=true line if $d\le 20$, or meaning your click is inside of the circle? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.