wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Testing

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Function definitions in Python start with what keyword?

a)

def

b)

fun

c)

function

d)

define

2.

A function parameter is a kind of variable accessible...

a)
within the function body
b)
outside the function body
c)
only by the main function
d)
in a separate file
3.

Which two statements are true?

a)

The return keyword forces a function to restart its execution

b)

The return keyword may cause the function to return a value

c)

The return keyword forces the function's execution to terminate

d)

The return keyword can only appear once inside a function

4.

What is the output of the following Python code?

tup = (1, ) + (1, )

tup = tup + tup

print(len(tup))

a)

2

b)

4

c)

0

d)

the snippet causes an error

5.

What is the output of the following code if the user enters "kangaroo" as their first prompt and 0 as their second?

a)

Error.Error.Error

b)

4.0

c)

Do not divide by Zero!

d)

Wrong value.

6.

What is the expected behaviour of the following snippet if the user enters 0?

value = input("Enter a value: ")

print(10 / value)

a)

The program will raise a ValueError exception

b)

The program will raise the ZeroDivisionError exception

c)

The program will raise the TypeError exception

d)

The program will output 0 to the console

7.

What is the output of the following Python code?

list = [1, 2, 3, 4]

print(list[4])

a)

4

b)

1

c)

the snippet causes an IndexError

d)

None

8.

What is the expected behaviour of the following snippet if the user enters a string?

value = input("Enter a value: ")

print(10 / int(value))

a)

The program will raise a ValueError exception

b)

The program will raise the ZeroDivisionError exception

c)

The program will raise the TypeError exception

d)

The program will output 0 to the console

9.

What is the expected behaviour of the following snippet if the user enters a negative number?

value = input("Enter a value: ")

print(10 / int(value))

a)

The program will raise a ValueError exception

b)

The program will output a negative number to the console

c)

The program will raise the TypeError exception

d)

The program will output 0 to the console

10.

What is the expected behaviour of the following snippet if the user enters a string?

value = input("Enter a value: ")

print(value.isnumeric())

a)

The program will raise a ValueError exception

b)

The program will output False to the console

c)

The program will raise the TypeError exception

d)

The program will output True to the console