Font size
WorksheetsPython Functions
Total questions: 20
Worksheet time: 12mins
Which two (2) lines of code will print when this function is called?
What is the name of the function?
When defining a function, the definition must occur before it is called.
true
false
What does the following code output?
11, 9
16, 16
None, None
225, 117
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
Which of the following is the correct code to define a function?
def area ( ):
area ( )
def area:
def area ( )
How do you identify the statements that belong to the body of a function?
Indent those statement the same amount underneath the function "def" statement
Add opening and closing curly braces { and } to mark the start and stop of the function body
Add the "def" keyword to the beginning of each statement
Add the same comment (#) to the right of each statement within the body
What character should be placed at the end of the function "def" line, after the parentheses?
Hashtag (#)
Colon(:)
Exclamation (!)
Dash (-)
Which keyword marks a spot in a function where the program flow will go back to the calling code?
break
return
continue
jump
If a function named "mystery" is defined as taking no parameters, how would you call that function from your code?
#mystery
mystery[]
mystery()
mystery
Which of the following best describes where you should define your function in your code?
Near the bottom of the source file, after that function is called by any main program code
Always place functions in a separate source file
Near the top of the source file, before that function is called by any main program code
The location is not important, so place the function wherever you like
Which of the following is NOT a Python rule for naming functions?
Functions names can contain letters, numbers and underscores
Function names must be less than 32 characters
The first character in a function name cannot be a number
Function names are case-sensitive
Which of the following statements correctly defines a function named "haunted" that takes a parameter named "apple"?
haunted(apple)
haunted
def haunted(apple):
apple
. Which of the following definitions for the "haunted" function will correctly set the default value for the "surprise" parameter equal to the number 1?
haunted(fear, surprise) = 1
def haunted(fear, surprise=1):
def haunted(fear, surprise "1")
def haunted[fear, surprise=1]
Which of the following statements will successfully send the value "EEK" back from a function to the calling code?
EEK
return EEK
back EEK
#print(EEK)
How many return statements can you place inside one function body?
As many as needed; each marks a spot where program flow returns to the calling code
You can have one return statement per parameter that is defined by the function "def"
You are limited by the number of body statements, divided by 2
Exactly one
What controls a variable's scope?
The location where it is first initialized within your code
The comment you place to the right of the variable name
The capitalization you select for the letters in your function name
The length of your variable name
Which of the following rules is true about locally scoped variables?
Local variables can hold less data than global variables
Local variables can be seen and accessed from any part of the program code
Local variables will keep their same value over repeated calls to the function
Local variables can only be seen and used from inside a function
