wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python {rogramming

Total questions: 45

Worksheet time: 29mins

Name
Class
Date
1.

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

2.

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.

3.

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.

4.

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.

5.

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.

6.

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

a)

left(90)

b)

right(180)

c)

left(180)

d)

left(360)

7.

What shape will be drawn with the following command?

circle(50, 360, 3)

(careful)

a)

A circle

b)

A hexagon

c)

A triangle

d)

A diamond

8.

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

for i in range(5):

forward(10)

a)

50 spaces

b)

60 spaces

c)

10 spaces

d)

5 spaces

9.
The number or word we give to a variable
a)
Value
b)
Bug
c)
Information
d)
Text
10.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
11.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
12.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
13.

What syntax would you use to create a name variable?

a)

name=input()

b)

input=name

c)

name=input{}

d)

name=INPUT

14.

Python is a _____________ side programming language.

a)

client

b)

server

c)

west

d)

east

15.

What is the proper syntax for Python comments?

a)

<!-- Python comment -->

b)

<comment> Python comment <comment>

c)

# Python Comment

d)

/* Python Comment */

16.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
17.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
18.

Which operator checks if a value is equal to another value?

a)

+

b)

=

c)

==

d)

!=

19.
a data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulo
d)
interpreter
20.

Which of these is true?

a)

A syntax error will stop a program running

b)

A logic error will stop a program running

c)

A syntax error will let the program run but may have unexpected outcomes

d)

The program will always show an error message for a logic error

21.

If Tracy starts at the left edge of the canvas and moves forward 50 pixels, how many times will this code need to be repeated to have Tracy reach the right edge of the canvas?

a)

4 times

b)

8 times

c)

12 times

d)

16 times

22.

Why do certain words change color in Python?

a)

To show that they are recognized as key words.

b)

To tell you that these words cannot be used in Python code.

c)

To show you that these words can be clicked.

d)

To tell Python to skip these words when running the code.

23.

If I use the command right(180), which way will Tracy turn?

a)

She will turn in a circle.

b)

She will turn around.

c)

She will turn to face up

d)

She will turn to face left

24.

If you wanted Tracy to complete her command immediately, which speed value would you use?

a)

10

b)

5

c)

1

d)

0

25.

Tracy always starts facing which direction?

a)

North

b)

South

c)

East

d)

West

26.

If Tracy started facing right, which direction would she be facing after we ran the following code?

left(90)

left(90)

right(90)

a)

up

b)

down

c)

right

d)

left

27.

What are the dimensions of Tracy’s world?

a)

100 x 100

b)

200 x 200

c)

200 x 400

d)

400 x 400

28.

In a guessing game, what will the following code snippet output if guess is '15' and number is 15?

a)

Correct!

b)

Incorrect!

c)

Syntax Error

d)

AttributeError

29.

Which operator should be used in place of "?" to make the following expression evaluate to True? (5 ? 3) and (2 < 4)

a)

>

b)

<=

c)

!=

d)

==

30.

In Python, what symbol is used to begin a comment?

a)

//

b)

/*

c)

#

31.

Match the vocabulary with the BEST example.

a)

IDE

1.

VSCode

b)

Module

2.

import random

c)

Keyword

3.

def

d)

Method

4.

random.randint()

e)

Modulo

5.

%

32.

What is the output of the following code snippet?

a)

97

b)

96

c)

86

d)

15

e)

14

33.

What will be the value of total at the end of the program?

a)

10

b)

9

c)

8

d)

7

e)

6

34.

What is the output of the following program?

a)

Grtings

b)

GRTINGS

c)

Greetings

d)

GREETINGS

e)

There is an error when the program is run.

35.

How does Python interact with the hardware of a computer?

a)

Directly interacts with the hardware

b)

Uses an interpreter to translate high-level code into machine code

c)

Uses a compiler to translate high-level code into machine code

d)

Does not interact with the hardware at all

36.

What does the abstraction in Python allow programmers to do?

a)

Focus on writing hardware-specific code

b)

Focus on writing code without dealing with hardware-specific details

c)

Directly interact with the hardware

d)

Create low-level machine code

37.

What is the primary use of the print command in Python?

a)

To accept user input.

b)

To display output to the console.

c)

To compile the code.

d)

To create a graphical user interface.

38.

Which of the following is true about the input() function in Python?

a)

It is used to display output to the console.

b)

It pauses the program and waits for the user to type something and press Enter.

c)

It is used to compile the code.

d)

It is used to create a graphical user interface.

39.
Which statement will cause an error?
a)
print("2" + 3)
b)
print(2 * 3)
c)
print(2 * "3")
d)
print("2" * 3)
40.
Which statement will cause an error? The variable name has been previously defined as name = "Susan".
a)
print("Hello" + Susan)
b)
print("Hello", name)
c)
print("Hello " + name)
d)
print(f"Hello {name}")
41.

Based on the following code, what gets printed to the screen?

greeting = 7

name = "Bob"

greeting = "Hello"

print(type(greeting))

a)
7
b)
<class 'int'>
c)
"Hello"
d)
<class 'str'>
42.

What kind of data does an string contain?

a)

Whole numbers

b)

Letters, special characters, numbers, or words

c)

Numbers with decimal components

d)

True or False

43.

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?

a)

user_age

b)

uSeRaGe

c)

user!age!

d)

1user_age

44.

On which line of code will Python error?

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

45.

What will the following program print when run?

a)

Issue Driver’s License

b)

Almost eligible for Driver’s License

c)

No requirements met

d)

Nothing will print