1
2
3
4
5
6
7
8
9
10
11
12
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
To pass information back from a function to the code that called it, you use the keyword ______ | return | ^ *return *$ | |
The calling code needs to provide a _______ that will receive the value that is returned by the function. | variable | ^ *variable *$ | |
To pass the result of the math operation back to the calling code, code the last line of the function. | def calc(): total = 2 + 2 | return total | return `total |
Call the function calc, which will return a value. The variable that will receive the returned value is named result. | result = calc() | result = calc() | |
Code a function, named trivial, that does nothing but pass the value 2 back to the calling code. | def trivial(): return 2 |
^ *def trivial\(\):\n return 2 *$ | |
Call a function that receives a value returned by the function. The function call has no arguments. Make everything up. | result = calc() | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\(\) *$ | |
Code a function that adds 2 plus 2, assigns the result to a variable, and passes the result back to the calling code. Make up the function name and variable. | def calc(): tot = 2 + 2 return tot |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n ([a-zA-Z_][a-zA-Z0-9_]*) = 2 \+ 2\n return \1 *$ | |
This time, code a function that adds 2 + 2, but condense the code into two lines. Don't assign 2 + 2 to a variable. Pass the result itself back to the calling code. Make up the name of the function. | def calc(): return 2 + 2 |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n return 2 \+ 2 *$ | |
Call a function, but this time, instead of assigning the returned value to a variable, just display the returned value. Make up the name of the function. Code the function and the print statement in a single line. | print(calc()) | ^ *print\([a-zA-Z_][a-zA-Z0-9_]*\(\)\) *$ | |
Code a three-line function that creates a list with three integers. Pass the list back to the calling code. Make everything up. | def make_list(): numbers = [12, 24, 36] return numbers |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n ([a-zA-Z_][a-zA-Z0-9_]*) = \[-?[0-9]+, -?[0-9]+, -?[0-9]+\]\n return \1 *$ | |
|
78c52d539f | ||
|
e7ef534476 |