wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python

Total questions: 25

Worksheet time: 50mins

Name
Class
Date
1.

When the following for loop is complete, how many spaces will Tracy have moved?

a)

50 spaces

b)

60 spaces

c)

10 spaces

d)

5 spaces

2.

Suppose you write a function. How many times can you call the function in your code?

a)

Once

b)

Not more than the number of commands the function holds

c)

It depends on the function

d)

As many times as you want

3.

In which of the following situations would it be best to make a function?

a)

You want Tracy to draw a blue line, and your program requires lots of blue lines.

b)

You need Tracy to move forward by 100.

c)

You need Tracy to turn right and then turn left.

d)

You need to change Tracy’s color.

4.

Which of the following pieces of code will make Tracy do the following actions three times: go forward, change colors, and then turn around.

a)
b)
c)
d)
5.

Suppose you want to make Tracy draw a mountain range, like the one shown below, starting from the left side. Which of the following functions would be the most useful function to write in order to solve this problem?

a)

# Has Tracy draw a single triangle

def make_triangle():

b)

# Change's Tracy's color to red

def change_to_red():

c)

# Moves Tracy forward by 100

def move_100():

d)

# Draws a square

def my_function():

6.

Which of the following is NOT a command you can give to Tracy?

a)

color

b)

turn

c)

backward

d)

left

7.

Which of the statements below is true about indentation in Python?

a)

Indentation only matters in for loops. Then, everything must be indented one level.

b)

Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.

c)

Indentation always matters in Python. Every statement must be aligned correctly.

d)

Indentation only matters in functions. Then, everything must be indented one level.

8.

Which of the following statements are true about for loops?

I. By default, the range function starts at 0

II. Using for i in range(4) will result in i taking the values 0, 1, 2, 3, 4

III. For loops let you repeat something any number of times

IV. Statements in a for loop do not need to be indented

V. It is not possible to have the range value count 6, 12, 18, 24

VI. It is not possible to have the range values count 1, 2, 4, 8, 16

a)

I, III, VI

b)

I, II, III, VI

c)

I, II, III, V, VI

d)

I, III

9.

Which of the following functions is declared correctly?

a)
b)
c)
d)
10.

Which of the following is NOT a purpose of using functions?

a)

Functions let Tracy do new things.

b)

Functions help group statements together to make your code more readable.

c)

Functions let you execute code a fixed number of times.

d)

Functions allow the programmer to reuse code.

11.

What is the difference between defining and calling a function?

a)

Defining a function means you are teaching the computer a new word. Calling a function means you are commanding the computer to complete defined actions.

b)

There is no difference.

c)

Calling a function means you are teaching the computer a new word. Defining a function means you are commanding the computer to complete defined actions.

d)

Defining a function must be done each time you want to use the function. Calling a function can only happen once in your code.

12.

What does the number in the parentheses in a forward or backward command represent?

a)

How many degrees Tracy is supposed to turn

b)

How fast Tracy is supposed to move

c)

How many times Tracy should repeat the command

d)

How far Tracy is supposed to move

13.

What control structure would be best to use in the following code?

a)

A function

b)

A while loop

c)

A for loop

d)

An if/else statement

14.

Which of the following commands can be used to turn Tracy to face North if she is initially facing South?

a)

left(90)

right(90)

b)

right(180)

c)

right(90)

left(180)

d)

left(360)

15.

Which program below includes no errors?

a)
b)
c)
d)
16.

Which of the following commands can NOT be used to draw one square?

a)
b)
c)
d)
17.

What shape will be drawn with the following command?

circle(50, 360, 3)

a)

A circle

b)

A hexagon

c)

A triangle

d)

A diamond

18.

How can we use variable to control the size of a circle?

a)

radius = 50

circle(radius)

b)

radius = circle(50)

c)

circle(radius)

radius = 50

d)

radius = 50

circle(50)

19.

Can a user’s input control the size of a circle? If so, how?

a)

No, user input is a string.

b)

Yes

circle(user_input=50)

c)

Yes

radius = int(input("Radius: "))

circle(radius)

d)

Yes

radius = input("Radius: ")

circle(radius)

20.

What is the most effective way to draw three circles in a row of different colors?

a)
b)
c)
d)
21.

What will be the output of the following program?

a)

Three circles with radii of 3, 7 and 2.

b)

Three shapes- a triangle (3 sides), a heptagon (7 sides), and a line (2 sides).

c)

Three shapes- a triangle (3 sides), a pentagon (5 sides), and a heptagon (7 sides).

d)

Two shapes- a triangle (3 sides) and a pentagon (5 sides).

22.

What will be the radii of the circles drawn from the following code?

a)

10, 20, 30, 40, 50

b)

10, 15, 20, 25, 30, 35, 40, 45, 50, 55

c)

10, 55, 10

d)

10, 20, 30, 40, 50, 55

23.

Which command will Tracy perform when given the following code?

a)

forward(200)

b)

backward(200)

c)

forward(201)

d)

backward(201)

24.

Which command will Tracy perform when given the following code?

a)

forward(10)

b)

backward(10)

c)

backward(10)

circle(10)

d)

circle(10)

25.

What will be the output of the following code?

a)

5 circles in a row

b)

4 circles in a row

c)

A slinky with 5 circles

d)

An infinite loop will occur