In a previous lesson, you learned how to use the input() function to
read text from the keyboard. What about the mouse, which is another extremely important way of
interacting with the computer?
There's another function dedicated to reading the mouse call mouse(). Unlike the input() function
which returns the text typed at the keyboard, the mouse() function returns two
values, the $x$ and $y$ coordinates of where the mouse was clicked. Here's how the function works:
Move the mouse over a dotted box for more information.
Now you try. Run this code several times, clicking on different regions of the output window. Does the mouse()
function seem to be reading your click position?
Type your code here:
See your results here:
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:
Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.
Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into
Then click the "Use on iPhone" button that you'll see.