wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Revision

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

What is the syntax for an if statement in Python?

a)

if [condition]

b)

if (condition)

c)

if {condition}

d)

if condition:

2.

Which loop in Python is used to iterate over a sequence of elements?

a)

for

b)

do-while

c)

if

d)

while

3.

What is the purpose of a function in Python?

a)

The purpose of a function in Python is to execute a single line of code.

b)

The purpose of a function in Python is to create a loop.

c)

The purpose of a function in Python is to encapsulate a set of instructions or code into a reusable block.

d)

The purpose of a function in Python is to print a message to the console.

4.

How do you declare a variable in Python?

a)

By using the division operator (/)

b)

By using the addition operator (+)

c)

By using the multiplication operator (*)

d)

By using the assignment operator (=)

5.

What is the data type of the variable 'x' in the following code: x = 5

a)

float

b)

integer

c)

string

d)

boolean

6.

What is the result of the following expression: 10 > 5

a)

true

b)

false

c)

10

d)

5

7.

What is the keyword used to define a function in Python?

a)

function

b)

def

c)

var

d)

class

8.

What is the output of the following code: print('Hello, World!')

a)

Hello

b)

World

c)

print('Hello, World!')

d)

Hello, World!

9.

What is the data type of the variable 'name' in the following code: name = 'John'

a)

integer

b)

boolean

c)

float

d)

string

10.

What is the output of the following Python code: print(5 + 3)

a)

8

b)

53

c)

5 + 3

d)

None of the above

11.

What is the data type of the variable 'pi' in the following code: pi = 3.14

a)

integer

b)

float

c)

string

d)

boolean

12.

What keyword is used to halt a function and go back to the calling code?

a)

stop

b)

base case

c)

quit

d)

return

13.

Every time you _ a function, the indented statements are run.

a)

return

b)

use

c)

call

d)

print

14.

Which function has the correct function syntax?

a)
b)
c)
d)
15.

What is the output?

a)

None

b)

98

c)

17

d)

72

16.

How to create a function in Python

a)

def myFunction():

b)

create myFunction():

c)

define myFunction():

d)

make myFunction():

17.
What will print ?
a)
cats eat mice
b)
mice get away
c)
unknown
d)
error message
18.

You assign a value to a variable with which symbol

a)

@

b)

==

c)

=

d)

*

19.

What is the output from the following code:

a)

[3,2,6,1,Dave]

b)

[Dave,3,2,6,1]

c)

[3,2,6,1,'Dave']

d)

['Dave',3,2,6,1]

20.

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

21.

Which of the following is the correct code to define a function?

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

22.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
23.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C