wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Chapter 12 Exam Review

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

How do you identify the statements that belong to the body of a function?

a)

Indent those statement the same amount underneath the function "def" statement

b)

Add the "def" keyword to the beginning of each statement

c)

Add opening and closing curly braces { and } to mark the start and stop of the function body

d)

Add the same comment (#) to the right of each statement within the body

2.

What character should be placed at the end of the function "def" line, after the parentheses?

a)

Hashtag (#)

b)

Colon (:)

c)

Exclamation (!)

d)

Dash (-)

3.

Which keyword marks a spot in a function where the program flow will go back to the calling code?

a)

continue

b)

jump

c)

return

d)

break

4.

If a function named "mystery" is defined as taking no parameters, how would you call that function from your code?

a)

mystery

b)

mystery()

c)

# mystery

d)

mystery[ ]

5.

Which of the following best describes where you should define your function in your code?

a)

Near the top of the source file, before that function is called by any main program code

b)

Near the bottom of the source file, after that function is called by any main program code

c)

Always place functions in a separate source file

d)

The location is not important, so place the function wherever you like

6.

Given the code below, which printed output will appear first when the code runs?

a)

BOO

b)

I'm not afraid of ghosts

c)

Syntax error - haunted() is not a valid function name

d)

Runtime exception - the haunted() function is called with incorrect parameters

7.

Which of the following is NOT a Python rule for naming functions?

a)

Function names must be less than 32 characters

b)

Function names can contain letters, numbers and underscores

c)

The first character in a function name cannot be a number

d)

Function names are case-sensitive

8.

Which of the following statements correctly defines a function named "haunted" that takes a parameter named "fear"?

a)

def haunted:fear

b)

function haunted[fear]:

c)

def haunted(fear):

d)

haunted("fear")

9.

Given the "haunted" function defined below, which of the following statements will correctly call the function and set the "fear" parameter equal to 10 and the "surprise" parameter equal to 5?

a)

haunted(10,5)

b)

haunted[10:5]

c)

haunted(5,10)

d)

haunted(range(10,5))

10.

Which of the following definitions for the "haunted" function will correctly set the default value for the "surprise" parameter equal to the number 1?

a)

def haunted(fear,=1):

b)

def haunted(fear, surprise "1")

c)

haunted(fear, surprise) = 1

d)

def haunted(fear, surprise=1):

11.

Which of the following function definitions allows values for the two parameters to be specified by names as shown below? haunt(surprise=5, fear=10)

a)

def haunt(fear, surprise):

b)

def haunt("fear","surprise");

c)

def haunt([fear], [surprise])

d)

haunt(surprise, fear)

12.

Which of the following statements will successfully send the value "EEK" back from a function to the calling code?

a)

final "EEK"

b)

return "EEK"

c)

"EEK".return()

d)

result["EEK"]

13.

If given the "haunt" function defined below, which of the following statements is valid?

def haunt(fear, surprise):

return fear * surprise

a)

haunt(1,2)

b)

result = haunt(1,2)

c)

print( str.format("Your scare result is {}",haunt(1,2)) )

d)

All of these are valid

14.

How many return statements can you place inside one function body?

a)

As many as needed; each marks a spot where program flow returns to the calling code

b)

Exactly one

c)

You are limited by the number of body statements, divided by 2

d)

You can have one return statement per parameter that is defined by the function "def"

15.

What controls a variable's scope?

a)

The length of your variable name

b)

The comment you place to the right of the variable name

c)

The capitalization you select for the letters in your function name

d)

The location where it is first initialized within your code

16.

Which of the following rules is true about globally scoped variables?

a)

Global variables are valid as long as your program is running

b)

Global variables can only be accessed from within the function where they were defined

c)

Global variables will be destroyed after each function ends

d)

After you initialize a global variable, you cannot change the value later

17.

Which of the following rules is true about locally scoped variables?

a)

Local variables can only be seen and used from inside a function

b)

Local variables will keep their same value over repeated calls to the function

c)

Local variables can be seen and accessed from any part of the program code

d)

Local variables can hold less data than global variables

18.

Given the code, which answer correctly matches the variable name and the scope type?

a)

name is global, attitude is local

b)

attitude is global, name is local

c)

name and attitude are both local

d)

name and attitude are both global

19.

What will be printed to the screen when the code runs?

a)

Creeper

b)

Casper

c)

ghost

d)

CasperCreeper

20.

What will be printed to the screen when the code runs?

a)

Phantastic

b)

ghost

c)

Slimer

d)

name