Lesson goal: Getting input from the mouse

Previous: Reading text from the keyboard | Home | Next: Square roots and the distance formula

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:
x,y=mouse()
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: