Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following is false about naming functions and parameters?

a)

Names can have spaces.

b)

Names can have digits.

c)

Some names are reserved by python.

d)

Names cannot start with digits.

2.

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)

a)

drawPrettyStar(5, 30, 'red')

b)

drawPrettyStar(5, 'blue', 40)

c)

drawPrettyStar('purple', 20, 35)

d)

drawPrettyStar('4', '5', blue)

3.

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)

a)

numberOfPoints

b)

radius

c)

color

d)

fill

4.

Which of the following calls to onMousePress will do nothing? def onMousePress(mouseX, mouseY): if (mouseX != mouseY): Circle(mouseX, mouseY, 10, fill='mediumVioletRed')

a)

onMousePress(100,200)

b)

onMousePress(100,400)

c)

onMousePress(200,100)

d)

onMousePress(300,300)

5.

Which of the following is a valid call to the function g and will have f(x) called 3 times?

a)

g(5, 10)

b)

g(10, 5)

c)

g(4, 5)

d)

g(4, 10)

6.

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)

a)

if(mouseY <= 200)

b)

if(mouseY <= 100)

c)

if(mouseX <= 100)

d)

if(mouseX <= 200)

7.

Read through the following lines of code that contains an error. What should be done to fix the error?

a)

The Rect function is not called correctly and needs an extra parameter.

b)

The draw function is defined incorrectly since you cannot define a function without parameters.

c)

The draw function is called too early. Line 1 should be on Line 5.

d)

There are no errors with the code as it is.

8.

Which of the following can be using to shorten the code on Lines A and B to be contained with one line of code?

a)

else if b == True

b)

else b == True

c)

elif b == True

d)

if b == True

9.

Which of the following is a true statement about how many parameters a function can use in its declaration?

a)

None – functions can never contain parameters

b)

One – functions can only contain one parameter

c)

Multiple – functions can contain multiple parameters as long as they are real words in the English language

d)

Multiple – functions can contain as many parameters as needed

10.

Read through the following lines of code that contains an error. What should be done to fix the error?

a)

Line 3 needs to be fixed. Conditional statements use == for equivalent conditions.

b)

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.

c)

Line 3 is missing parentheses around the condition. Conditional statements always include parentheses.

d)

Line 2 is missing a declaration of the variable b. The conditional statement will have an error with only one variable.