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
Write the header of the onKeyPress function
def onKeyPress(key):
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
What type of shape can addPoint() be called on?
Polygon
Name 2 position properties
centerX, centerY, left, top, bottom, right
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
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
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
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()
Which of control structure will always execute SOMETHING:
a. if
b. if-elif
c. if-elif-else
C
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
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
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'
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))
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
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
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
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
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))
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
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
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
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'
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'
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