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
The code for a function called by another function must be placed before or after the code that calls it? | before | ^ *before *$ | |
Below is a function that calls another function. Code the first line of the called function. Its parameter is named number. | def call_another_function() calc(50) |
def calc(number): | ^ *def calc\(number\): *$ |
The function that is being called needs to know the value of x. Rewrite the third line of this function so the function being called knows it. | def do_something(): x = 101 calc(): | calc(x) | calc`(`x`) |
What is the parameter name of the function called by this code? | calc(number = -5) | number | number |
Code the first line of the function that is being called. Make up the parameter name. | analyze("O'Leary") | def analyze(name): | ^ *def analyze\([a-zA-Z_][a-zA-Z0-9_]*\): *$ |
Replace the second line of this code with a function call. Make up the function name. Remember to indent. | def x(): y = "boogie" + "woogie" |
y = combine("boogie", "woogie") | ^ ? ?y = [a-zA-Z_][a-zA-Z0-9_]*\(•boogie•, •woogie•\) *$ |
The function being called displays the result of dividing the first number by the second number. Code the function using just two lines of code. | calc(x = 12, y = 3) | def calc(x, y): print(x / y) |
^ *def calc\(x, y\):\n print\(x / y\) *$ |
The function being called returns the result of dividing the first number by the second number. Code the function using just two lines of code. Make up the parameter names. | result = calc(12, 3) | def calc(x, y): return x / y |
^ *def calc\(([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*)\):\n return \1 / \2 *$ |
Code a function that calls this function. Pass two keyword arguments that are integers. Make everything up. | def calc(**numbers): for a_number in numbers.values(): print(a_number) |
def calls_another_function(): calc(first_number = 12, second_number = 1400) |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n calc\([a-zA-Z_][a-zA-Z0-9_]* = -?[0-9]+, [a-zA-Z_][a-zA-Z0-9_]* = -?[0-9]+\) *$ |
Rewrite this code, replacing 2 + 4 with a function call that includes the two numbers as parameters and does the math. Make up the function name. | def calc(): return 2 + 4 |
def calc(): return do_math(2, 4) |
^ *def calc\(\):\n return [a-zA-Z_][a-zA-Z0-9_]*\(2, 4\) *$ |
|
68233d43b5 | ||
|
d39d4b4278 |