wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Functions

Total questions: 20

Worksheet time: 12mins

Name
Class
Date
1.

Which two (2) lines of code will print when this function is called?

4 lines
2.

What is the name of the function?

4 lines
3.

When defining a function, the definition must occur before it is called.

a)

true

b)

false

4.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
5.

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

6.

Consider the line of code:

Label('Go Team', 200, 100)

What is the Label?

a)

argument

b)

parameter

c)

function name

7.

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

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

8.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
9.

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 opening and closing curly braces { and } to mark the start and stop of the function body

c)

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

d)

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

10.

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

a)

Hashtag (#)

b)

Colon(:)

c)

Exclamation (!)

d)

Dash (-)

11.

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

a)

break

b)

return

c)

continue

d)

jump

12.

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

13.

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

a)

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

b)

Always place functions in a separate source file

c)

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

d)

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

14.

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

a)

Functions names can contain letters, numbers and underscores

b)

Function names must be less than 32 characters

c)

The first character in a function name cannot be a number

d)

Function names are case-sensitive

15.

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

a)

haunted(apple)

b)

haunted

c)

def haunted(apple):

d)

apple

16.

. 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)

haunted(fear, surprise) = 1

b)

def haunted(fear, surprise=1):

c)

def haunted(fear, surprise "1")

d)

def haunted[fear, surprise=1]

17.

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

a)

EEK

b)

return EEK

c)

back EEK

d)

#print(EEK)

18.

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)

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

c)

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

d)

Exactly one

19.

What controls a variable's scope?

a)

The location where it is first initialized within your code

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 length of your variable name

20.

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

a)

Local variables can hold less data than global variables

b)

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

c)

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

d)

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