NEW
Font size
WorksheetsFunctions in Python
Total questions: 28
Worksheet time: 24mins
Which statement is the function definition?
def square(x):
return a
a = pow(x,2)
The function definition line must end with a
semi-colon
colon
parenthesis
Give your function a name that
describes what it does
is easily remembered
is the title of a nursery rhyme
When you use your function in your program, that is called the function
definition
call
return
When you call your function in your program, you say its name followed by
parenthesis
colon
semi-colon
Inside the parenthesis of the function call you can send the ____________ your function will use.
arguments
answers
methods
You may call a function inside another function.
True
False
You must put your function definition
at the end of your program
in a separate file
at the beginning of your program
What word causes a function to stop?
return
end
stop
The DRY principle means
don't repeat yourself
use functions so that you don't write the same code over and over
both answers are correct
Bad, repetitive code is said to abide by the WET principle, which stands for
Write Everything Twice
We Enjoy Typing
Both answers are correct
The words in front of the parentheses are function names, and the comma-separated values inside the parentheses are function
definitions
arguments
calls
The code block that defines a function is indented
true
false
Variables created inside a function definition can be used in other parts of the program.
true
false
It is common practice to put a comment containing an explanation of the function below the function's first line.
true
false
Modules are pieces of code that other people have written to fulfill common tasks, such as generating random numbers, performing mathematical operations, sorting lists, appending to lists, etc
true
false
We use modules by using the ________ command at the top of our program
import
export
def
To import only the pi constant from the math module use the following code:
from math import pi
import math.pi
import pi_math
When using a module like sort or append, the format is
list.sort
list(sort):
What will print?
nothing
5
6
an error message
