wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python - Syntax, Functions and Control Flow

Total questions: 28

Worksheet time: 14mins

Name
Class
Date
1.

What happens when running the following code?

a)

"message" is printed.

b)

"What a cool message!" gets printed to the console.

c)

Python throws a SyntaxError because the string is not surrounded by quotes.

2.

How does one define a multi-line string in Python?

a)

***

Like

This

***

b)

"""

Like

This

"""

c)

###

Like

This

###

3.

Which of the following defined variables is a string?

a)

cool_variable_1

b)

cool_variable_2

c)

cool_variable_3

d)

cool_variable_4

4.

Which function outputs text to the terminal?

a)

print()

b)

write()

c)

type()

d)

output()

5.

Which of the following will produce a SyntaxError?

a)
b)
c)
6.

What is the difference between a float and an int?

a)

A float can only be used with whole numbers. An int can be any number with a decimal point.

b)

A float contains text information. An int is any number.

c)

A float represents decimal quantities. An int represents whole numbers.

7.

How do you combine two strings?

a)

string1.concatenate(string2)

b)

string1.combine(string2)

c)

string1 + string2

8.

What is Python syntax for creating a variable and setting it equal to the number 10?

a)

def variable_name = 10

b)

variable_name == 10

c)

new variable_name = 10

d)

variable_name = 10

9.

What is the output of the following code?

a)

210

b)

42

c)

cool_number

10.

What number is saved to exponented_variable in the following expression?

a)

8

b)

16

c)

6

d)

24

11.

What character begins a comment in Python?

a)

%

b)

#

c)

*

d)

@

12.

What is the value of total_cost that gets printed?

a)

5

b)

15

c)

10

d)

50

13.

What is the value of modulo_variable in the following expression?

a)

56

b)

2

c)

3.5

d)

14.4

14.

What happens when you call report?

a)

Two Strings are printed: "The current time is " and "The mood is "

b)

One String is printed: "The current time is 3pm"

c)

Two Strings are printed: "The current time is 3pm" and "The mood is good"

d)

Three Strings are printed: "The current time is 3pm", "The mood is good", and "End of report"

15.

Which variables can be called in the blank spot in this code:

a)

Just new_counter

b)

Just counter

c)

counter and new_counter

d)

Neither counter nor new_counter

16.

What line of code can be used to return a variable inner_var from a function back to the piece of code that called the function?

a)

def inner_var

b)

print(inner_var)

c)

inner_var = None

d)

return inner_var

17.

How do you call a function called setup with no arguments?

a)

setup()

b)

setup(None)

c)

def setup():

d)

setup

18.

How do you call update with a new_value of 20?

a)

def update(20)

b)

update(20)

c)

update

d)

update()

19.

What line of code will call force with a value of 10 for mass and a value of 9.81 for acceleration?

a)

force(mass=10, 9.81)

b)

force(9.81, 10)

c)

force(10, mass=9.81)

d)

force(10, 9.81)

20.

Given the following function, what will produce the output "There is no greater agony than bearing an untold story inside you."?

a)

def quote("an untold story")

b)

quote()

c)

quote("an untold story")

d)

quote(an untold story)

21.

Which of the following variables contains a Boolean value?

a)
b)
c)
d)
22.

Which of the following is a Boolean expression?

a)

This quiz is very hard.

b)

Three is the most elegant number.

c)

The New York Yankees are the classiest baseball team.

d)

My name is Angelo.

23.

Determine the truth value of the following expressions:

a)

A: False

B: True

b)

A: False

B: False

c)

A: True

B: True

d)

A: True

B: False

24.

Determine the truth value of the following expressions:

a)

A: True

B: True

b)

A: False

B: True

c)

A: False

B: False

d)

A: True

B: False

25.

Consider the code. What would this print to the terminal?

a)

Nothing is printed.

b)

Is this printed?

c)

Is this printed?

This might be printed.

d)

This is printed.

This is also printed.

26.

What will the code print when it is executed?

a)

result

b)

A ValueError occurred.

c)

A ZeroDivisionError occurred.

d)

A NameError occurred.

27.

Determine the truth value of the following expressions:

a)

A: True

B: False

b)

A: True

B: True

c)

A: False

B: False

d)

A: False

B: True

28.

Read the following code carefully. What will happen when the code is executed?

a)

"x is equal to zero" will print to the terminal.

b)

There will be a ValueError.

c)

"x is equal to zero" and "x is greater than zero" will print to the terminal.

d)

There will be a SyntaxError.