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
Fill in the blank to add a parameter that receives optional positional arguments. Make up the name. | def do_something(school, state, ________): | *rank | ^ *\*[a-zA-Z_][a-zA-Z0-9_]* *$ |
Fill in the blank to add a parameter that receives optional keyword arguments. Make up the name. | def do_something(school, state, ________): | **rank | ^ *\*\*[a-zA-Z_][a-zA-Z0-9_]* *$ |
Call the function sort_out. Pass a keyword argument. The key is dict. The value is a variable, products. | sort_out(dict = products) | sort_out`(`dict `= `products`) | |
Code the first line of a function definition, analyze. qty is the parameter. 0 is the default. | def analyze(qty = 0): | def analyze(qty = 0): | |
This is the first line of a function definition. When optional arguments are passed, they're assigned to x, which is a ____________. | def fill_dictionary(new_customer, first_name, last_name, **x): | dictionary | ^ *dictionary *$ |
Code the first line of a function definition. It has a single parameter that receives optional positional arguments from the calling code. Make up the function name and the parameter name. | def calc(*numbers): | ^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\*[a-zA-Z_][a-zA-Z0-9_]*\): *$ | |
The fourth and last parameter holds optional keyword arguments that are passed by the calling code. Complete the line. Make up the argument name. | def a(b, c, d = 1, _________ | **more_details): | ^ *\*\*[a-zA-Z_][a-zA-Z0-9_]*\): *$ |
Code the first line of a function. Its only parameter holds optional keyword arguments. Make everything up. | def maybe_maybe_maybe_not(**optional_info): | ^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\*\*[a-zA-Z_][a-zA-Z0-9_]*\): *$ | |
I've coded the first line of a function. Tell Python to display each value in turn on a separate line. Start by displaying the value of the first parameter. The second line that you'll code is for value in extras.values(): Indent correctly. |
def show_things(name, **extras): | print(name) for value in extras.values(): print(value) |
^ * print\(name\)\n for value in extras\.values\(\):\n print\(value\) *$ |
Try it again, without help: I've coded the first line of a function. Tell Python to display each value in turn on a separate line. Make up the name of the variable that holds each value in the dictionary. Remember to indent. | def show_things(name, **extras): | print(name) for each_optional_name in extras.values(): print(each_optional_name) |
^ * print\(name\)\n for ([a-zA-Z_][a-zA-Z0-9_]*) in extras\.values\(\):\n print\(\1\) *$ |
|
9f5c63b7f8 | ||
|
ccae36e27b |