If/Elif/Else
Key Events
Custom Properties
Shape Methods
Miscellaneous
100

Consider the following:

if(statement1):

    #code for statement 1

elif(statement2):

    #code for statement 2

elif(statement3):

    #code for statement 3

else:

    #code for else

True or false: if statement1, statement2, and statement3 are all false, then the code for else will execute

True

100

Write the header of the onKeyPress function

def onKeyPress(key):

100

Consider the following:

button = Rect(0, 0, 20, 20)

Create a custom property for the button call isOn and set it to True

button.isOn = True

100

What type of shape can addPoint() be called on?

Polygon

100

Name 2 position properties

centerX, centerY, left, top, bottom, right

200

Consider the following:

if(statement1):

    #code for statement 1

elif(statement2):

    #code for statement 2

elif(statement3):

    #code for statement 3

else:

    #code for else

True or false: if statement1 is true, then the code for segment 1 will always execute

True

200

Consider the following code:

c = Circle(0, 0, 20)

c.power = 0

Write the code in the onKeyPress function that increases the power of c by 20 when the up key is pressed, and decreases the power of c by 20 when the down key is pressed.

def onKeyPress(key):

    if(key == 'up'):

        c.power += 20

    elif(key == 'down'):

        c.power -= 20

200

Consider the following:

r = Rect(0, 0, 20, 20)

r.power = 0

Write the code in the function below to increase the value of r.power by 10 every time the mouse is clicked.

def onMousePress(mouseX, mouseY):

r.power += 10

200

If you have a Circle called c, how can you make sure that no matter what other shapes are added to the canvas, c shows up on top of them? (Write the actual line of code to do this)

c.toFront()

200

Which of control structure will always execute SOMETHING:

a. if

b. if-elif

c. if-elif-else

C

300

Consider the following:

if(statement1):

    #code for statement 1

elif(statement2):

    #code for statement 2

elif(statement3):

    #code for statement 3

else:

    #code for else

True or false: if statement2 is true, then the code for segment 2 will always execute

False

300

Consider the following:

c = Circle(100, 200, 40)

def onKeyPress(key):    

    if (key == 'right'):        

        c.centerX += 50    

    elif (c.centerX > 200):        

        c.fill = 'orange'    

    elif (c.centerX > 100):        

        c.centerX -= 50

Given the initial position of c and the code above, what will c's centerX and fill be after the following key strokes:

right, right

200, black

300

Consider the following:

c = Circle(0, 0, 20)

c.hype = 0

Write a function call applyHype() that changes the fill of c based on the value of c.hype based on the following rules:

For a hype value less than 30: fill of blue

For a hype value between 30 (inclusive) and 70 (exclusive): fill of orange

For a hype value of 70 or more: fill of pink

def applyHype():

   if(c.hype < 30):

        c.fill = 'blue'

   elif(c.hype < 70):

        c.fill = 'orange'

   else:

        c.fill = 'pink'

300

Consider the following:

button = Circle(200, 200, 20, fill=None, border = 'black')

In the function below, how can you test to see if the Circle above was clicked?

def onMousePress(mouseX, mouseY):

if(button.contains(mouseX, mouseY))

300

Consider the following:

def f(x, isNight):    

    if (x > 100):        

        moon.fill = 'white'    

    elif (isNight== True):        

        moon.fill = 'skyBlue'    

    elif (x == 50):        

        moon.fill = 'gold'    

    elif (x == 60):        

        moon.fill = 'yellow'    

    else:        

        moon.fill = 'grey'


Which function call will set the fill of a Circle moon to white?

a. f(200, True) 

b. f(75, True) 

c. f(0, False) 

d. f(60, False)

A

400

Consider the following:

if(statement1):

    #code for statement 1

elif(statement2):

    #code for statement 2

elif(statement3):

    #code for statement 3

else:

    #code for else

True or false: if statement1 is false, then the code for statement 2 will execute

False

400

Consider the following:

c = Circle(100, 200, 40)

def onKeyPress(key):    

    if (key == 'right'):        

        c.centerX += 50    

    elif (c.centerX > 200):        

        c.fill = 'orange'    

    elif (c.centerX > 100):        

        c.centerX -= 50

Given the initial position of c and the code above, what will c's centerX and fill be after the following key strokes:

right, right, 'a'

150, black

400

Consider the following:

r = Rect(0, 0, 20, 20)

r.power = 0

Write the code in the function below to decrease the value of r.power by 3 if r is clicked

def onMousePress(mouseX, mouseY):

if(r.contains(mouseX, mouseY)):

   r.power -= 3

400

Consider the following:

button = Circle(200, 200, 20, fill = 'black')

In the function below, how can you test to see if the Circle above was clicked?

def onMousePress(mouseX, mouseY):

if(button.hits(mouseX, mouseY))

OR

if(button.contains(mouseX, mouseY))

400

Consider the following:

def f(x, isNight):    

    if (x > 100):        

        moon.fill = 'white'    

    elif (isNight== True):        

        moon.fill = 'skyBlue'    

    elif (x == 50):        

        moon.fill = 'gold'    

    elif (x == 60):        

        moon.fill = 'yellow'    

    else:        

        moon.fill = 'grey'


Which function call will set the fill of a Circle moon to yellow?

a. f(200, True) 

b. f(75, True) 

c. f(0, False) 

d. f(60, False)

D

500

Consider the following: 

app.isOn= True 

def onKeyPress(key):    

    if (app.isOn== True):        

        drawLight()    

    elif (key == 'up'):

        changeOnOrOff()    

    else:        

        drawPainting()

When does the code call the drawPainting() function? (assume the changeOnOrOff() function is defined and updates app.isOn)  

Never

500

Consider the following:

c = Circle(100, 200, 40)

def onKeyPress(key):    

    if (key == 'right'):        

        c.centerX += 50    

    elif (c.centerX > 200):        

        c.fill = 'orange'    

    elif (c.centerX > 100):        

        c.centerX -= 50

Given the initial position of c and the code above, what will c's centerX and fill be after the following key strokes:

right, right, 'a', right, right, left

250, orange

500

Consider the following:

r = Rect(0, 0, 20, 20)

r.power = 0

r.isDead = False

Write the code in the function below to change the value of r.isDead and change the fill of r to red if r.power becomes negative.  

def onMousePress(mouseX, mouseY):

if(r.power < 0):

    r.isDead = True

    r.fill = 'red'

500

Consider the following:

r = Rect(0, 0, 20, 20)

c = Circle(300, 300, 20)

Write the code in on mouse move to change the fill of the rectangle to gold if the two shapes intersect at all.

def onMouseMove(x, y):

    c.centerX = x

    c.centerY = y

    #insert code here

    

if(r.hitsShape(c)):

    r.fill = 'gold'

500

Consider the following:

def f(x, isNight):    

    if (x > 100):        

        moon.fill = 'white'    

    elif (isNight== True):        

        moon.fill = 'skyBlue'    

    elif (x == 50):        

        moon.fill = 'gold'    

    elif (x == 60):        

        moon.fill = 'yellow'    

    else:        

        moon.fill = 'grey'


Which function call will set the fill of a Circle moon to skyBlue?

a. f(200, True) 

b. f(75, True) 

c. f(0, False) 

d. f(60, False)

B