wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Unit 6 Review

Total questions: 11

Worksheet time: 8mins

Name
Class
Date
1.
Which of the following is the correct way to declare a function in Python?
a)
print_hello: print("hello")
b)
function print_hello(): print ("hello")
c)
print_hello(): print("hello")
d)
def print_hello(): print("hello")
2.
Which of the following code samples correctly passes the number 10 as an argument to the function print_number?
a)
print_number(10)
b)
print_number(), print 10
c)
10(print_number)
d)
print print_number, print 10
3.
Consider this code snippet. x = 10, def add_nums(): y = 2, z = x + y, print(z) Which of the following additional functions could be safely added to this code, without causing an error?
a)
def subtract_nums(): z = x - y, print(z)
b)
def subtract_nums():, z = z - x, print(z)
c)
def subtract_nums():, y = 5, z = x - y, print(z)
d)
def subtract_nums(): z = y, z = x - y, print(z)
4.
Which of the following functions successfully returns the number 10?
a)
def my_function(): 10
b)
def my_function(10): return
c)
def my_function(): return 10
d)
def my_function(): print(10)
5.
What type of error occurs when a program is expecting an integer value and the user enters a string?
a)
NumberError
b)
ValueError
c)
InputError
d)
ZeroDivisionError
6.
Why do programmers use try and except statements when their code might throw an exception?
a)
So that the programmer can disregard the exception and do what he/she wants anyways
b)
Because Python requires it
c)
To handle exceptions gracefully and either handle the error or print out a useful error message.
d)
Exceptions only are thrown when there are try and except statements. Otherwise, the program will just fail and the programmer will have no idea why it failed.
7.

Which of the programs below will print the following output?

I would like a green balloon.

a)

def balloon_choice(color): print("I would like a " + color + " balloon.") balloon_choice("green")

b)

def balloon_choice(color): print("I would like a " + color + " balloon.")

c)

def balloon_choice(): print("I would like a " + color + " balloon.") balloon_choice("green")

d)

def balloon_choice(): print("I would like a green balloon.") balloon_choice("green")

8.

What will be the output of the following program?

a)

12

b)

CODE

c)

4

d)

codecodecode

9.

Which of the following options is NOT a valid Python function definition?

a)

# computes the surface area of a cube of side length 10

# def surface_area(): return 2*(100 + 100 + 100)

b)

# computes the surface area of a rectangular prism

def surface_area(length, width=10, height): return 2*(length width + width height + height * length)

c)

# computes the surface area of a rectangular prism

def surface_area(length, width, height): return 2*(length width + width height + height * length)

d)

# computes the surface area of a rectangular prism

def surface_area(length, width, height=10): return 2*(length width + width height + height * length)

10.

What will be printed when the program below is run?

a)

12

b)

24

c)

50

d)

66

11.

Why do programmers use try and except statements when their code might throw an exception?

a)

So that the programmer can disregard the exception and do what he/she wants anyways

b)

Because Python requires it

c)

To handle exceptions gracefully and either handle the error or print out a useful error message.

d)

Exceptions only are thrown when there are try and except statements. Otherwise, the program will just fail and the programmer will have no idea why it failed.