Functions and Calls
Variables and Properties
Mouse Events and Methods
Conditionals and Debugging
100

Which Python keyword begins a function definition?

def

100

Name the property changed by this statement.

c.fill = 'blue'

fill

100

Name the event handler that runs when the mouse button is pressed.

onMousePress

100

Complete the Python comparison for “score equals 10.”

score ___ 10

==

200

What term names an input variable in a function definition?

Parameter

200

Complete the property name to hide the existing circle.

c._____ = False

visible

200

A program must act when the user lets go of a held mouse button. Name the event handler.

onMouseRelease

200

A program tries to create Circle(200, 200, -10). Its syntax is valid, but execution fails. Name the error type.

Runtime error

300

Give the new circle’s centerX.

def drawDot(x, y):
    Circle(y, x, 20)

drawDot(60, 140)

140

300

c is an existing circle. Give the final value of c.centerX.

c.centerX = 80
c.centerX += 30
c.centerX *= 2

220

300

Which shape method tests contact with another shape supplied as its argument?

hitsShape()

300

c is an existing circle. Give the final fill color.

score = 10

if (score > 10):
    c.fill = 'red'
elif (score == 10):
    c.fill = 'blue'
else:
    c.fill = 'green'

Blue

400

c is an existing circle. Give the final value of c.centerX.

c.centerX = 100

def shift(amount):
    c.centerX += amount

def twice(amount):
    shift(amount)
    shift(amount)

twice(15)
shift(-10)

120

400

c is an existing circle. Give the final value of c.centerX.

c.steps = 3
c.centerX = 100
c.centerX += c.steps * 10
c.steps += 2
c.centerX -= c.steps * 4

110

400

Give the Boolean value printed. The marked point is the center of the ring.

ring = Circle(200, 200, 60,
              fill=None, border='black')
print(ring.hits(200, 200))

False

400

Give the final value of x.

x = 5

if (x < 10):
    x += 10

if (x > 10):
    x -= 3
else:
    x += 1

12

500

c is an existing circle. Write moveDot(dx, dy) to add dx to c.centerX and dy to c.centerY. Include one call that makes the change shown.

def moveDot(dx, dy):
    c.centerX += dx
    c.centerY += dy

moveDot(30, -20)

One valid solution.

500

c is an existing circle. Start with c.centerX = 100 and c.step = 10. Write two statements for one update: move right by the current step, then double step. Give centerX after two updates.

c.centerX += c.step
c.step *= 2

After two updates: centerX = 130. One valid solution is shown.

500

c is the existing purple circle. Write a mouse-press handler that brings c to the front only when the press hits its drawn area.

def onMousePress(mouseX, mouseY):
    if (c.hits(mouseX, mouseY)):
        c.toFront()

One valid solution. A comparison with == True is also acceptable.

500

c is an existing circle. Required colors: red below 10; green from 10 through 19; blue at 20 or above. Correct this code. Give test inputs immediately below and at each boundary, with expected colors.

if (score >= 10):
    c.fill = 'green'

if (score >= 20):
    c.fill = 'blue'
else:
    c.fill = 'red'
if (score >= 20):
    c.fill = 'blue'
elif (score >= 10):
    c.fill = 'green'
else:
    c.fill = 'red'

Tests: 9 → red; 10 → green; 19 → green; 20 → blue. One valid correction is shown.