Search Header Logo
CMU CS Academy 2.2.4 and 2.2.5

CMU CS Academy 2.2.4 and 2.2.5

Assessment

Presentation

Computers

9th - 12th Grade

Practice Problem

Easy

Created by

Maria Cruz Farooqi

Used 3+ times

FREE Resource

2 Slides • 10 Questions

1

CMU CS Academy 2.2.4 and 2.2.5
Variables and Mouse Release Events

By Maria Cruz Farooqi

​Learning Target:
I can identify and utilize global and local variables to modify the properties of a shape in a graphical program.

I can use Python to change shapes when I release the mouse and explain what happens when I press and release the mouse in different ways.

2

Drag and Drop

Question image
What we want is to use only
circle. And for that, we need a way in our ​
function to refer to that circle. And for that, we need a ​
.
Drag these tiles and drop them in the correct blank above
one
onMousePress
global variable

3

Multiple Choice

How can we be sure that there are 2 circles after we click the mouse in the previous example?

1

We cannot. There is no way to tell.

2


The Inspector shows one point with two colors.

3

Both a red and a blue circle are clearly visible.

4


The circle is purple, because it combines blue and red.

4

Dropdown

Question image
What's happening here? Look at line 1, and you will see that instead of just calling Circle, we have ​
. When we create a shape, we can ​
. Here, we used the ​
c. After that, we can use c to get and ​
of that circle. For example, c.fill is the ​
. So the line c.fill = 'blue' sets the fill color of the circle to blue.

5

Dropdown

Question image
Run the code and press the mouse a few times.

See how the circle ​
to where you press the mouse. Now, look at lines 4 and 5. See how we use ​
to set the x and y ​ locations of the center of the circle.

6

Dropdown

Question image
The ​
c is not a function parameter. It is defined ​
of any function. We call a variable defined outside of any function a ​
variable. So c is a global variable.

Unlike local variables, global variables can be used anywhere, inside or outside any function. That is why we can use c inside ​

7

Multiple Choice

Which variables are local, and which are global, in the previous example?

1

x and y are local, and c is global.

2


They are all local.

3


They are all global.

4

c is local, and x and y are global.

8

Drag and Drop

onMouseRelease

When you press the mouse down, eventually you stop ​
. At that time, we say that you ​
the mouse. Then, Python calls ​
, if you wrote it.
Drag these tiles and drop them in the correct blank above
holding it down
release
onMouseRelease

9

Dropdown

Question image
Run the code. Press the mouse, move it around, then ​
. See how you get a ​
each time you press the mouse, and a ​
each time you release it.

10

Multiple Choice

In the previous example, what happens if you press the mouse and immediately release it (without moving it)? Try it first before answering.

1

We get two circles -- a navy circle drawn directly over a gold circle.

2

The code crashes if we do that.

3

We get only one circle -- the gold circle becomes navy.

4

There is no way to tell if we have one or two circles.

11

Dropdown

Question image
Run the code. Press the mouse, ​
for a while, and ​
it. See how the circle ​
when you press the mouse, and stays blue until you release it, when it ​
again. Nice!

12

media

​Your Turn: Go to CMU CS Academy and finish the lessons, Checkpoints, and Exercises.

CMU CS Academy 2.2.4 and 2.2.5
Variables and Mouse Release Events

By Maria Cruz Farooqi

​Learning Target:
I can identify and utilize global and local variables to modify the properties of a shape in a graphical program.

I can use Python to change shapes when I release the mouse and explain what happens when I press and release the mouse in different ways.

Show answer

Auto Play

Slide 1 / 12

SLIDE