WorksheetsPython Programming Quiz
Total questions: 10
Worksheet time: 5mins
Which of the following is false about naming functions and parameters?
Names can have spaces.
Names can have digits.
Some names are reserved by python.
Names cannot start with digits.
Which of the following would be a legal call for the code below? def drawPrettyStar(numberOfPoints, radius, color): Star(200, 200, radius, numberOfPoints, fill=color)
drawPrettyStar(5, 30, 'red')
drawPrettyStar(5, 'blue', 40)
drawPrettyStar('purple', 20, 35)
drawPrettyStar('4', '5', blue)
Using the same code segment from #2, which of the following is not a parameter of the function
drawPrettyStar?
def drawPrettyStar(numberOfPoints, radius, color):
Star(200, 200, radius, numberOfPoints, fill=color)
numberOfPoints
radius
color
fill
Which of the following calls to onMousePress will do nothing? def onMousePress(mouseX, mouseY): if (mouseX != mouseY): Circle(mouseX, mouseY, 10, fill='mediumVioletRed')
onMousePress(100,200)
onMousePress(100,400)
onMousePress(200,100)
onMousePress(300,300)
Which of the following is a valid call to the function g and will have f(x) called 3 times?
g(5, 10)
g(10, 5)
g(4, 5)
g(4, 10)
Which of the following results in a red rectangle being drawn when the mouse is moved in the left half of the canvas and a green rectangle being drawn when the mouse is moved elsewhere? (Assume the function drawRect will draw a rectangle given the color)
if(mouseY <= 200)
if(mouseY <= 100)
if(mouseX <= 100)
if(mouseX <= 200)
Read through the following lines of code that contains an error. What should be done to fix the error?
The Rect function is not called correctly and needs an extra parameter.
The draw function is defined incorrectly since you cannot define a function without parameters.
The draw function is called too early. Line 1 should be on Line 5.
There are no errors with the code as it is.
Which of the following can be using to shorten the code on Lines A and B to be contained with one line of code?
else if b == True
else b == True
elif b == True
if b == True
Which of the following is a true statement about how many parameters a function can use in its declaration?
None – functions can never contain parameters
One – functions can only contain one parameter
Multiple – functions can contain multiple parameters as long as they are real words in the English language
Multiple – functions can contain as many parameters as needed
Read through the following lines of code that contains an error. What should be done to fix the error?
Line 3 needs to be fixed. Conditional statements use == for equivalent conditions.
Line 5 needs to be fixed. This needs to have an else before it so that it can execute if the condition is not true.
Line 3 is missing parentheses around the condition. Conditional statements always include parentheses.
Line 2 is missing a declaration of the variable b. The conditional statement will have an error with only one variable.
