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
In the following code, what is the value of total if the function call doesn't pass any arguments? | def add_numbers(first_number = 2, second_number = 4): total = first_number + second_number |
6 | ^ *6 *$ |
In the following code, what is the value of total? | def add_numbers(first_number = 2, second_number = 4): total = first_number + second_number add_numbers(second_number = 10) |
12 | ^ *12 *$ |
Code the first line of a function, analyze, that has a single parameter, name, with a default of "Jones". | def analyze(name = "Jones"): | def `analyze`(`name `= `"`Jones`"`)`: | |
Code the first line of a function, x, that has two parameters, y and z. The first parameter has no default. The second parameter has a default of 1. | def x(y, z = 1): | def x(y, z = 1): | |
Rewrite this code so it's legal. | def x(y = 1, z): | def x(z, y = 1): The problem could be the parameter order, or could be something else. Parameters with defaults must come after parameters without defaults. Also, check your spacing. |
^ *def x\(z, y = 1\): *$ |
Code the first line of a function with one parameter whose default is a string. Make everything up. | def test(name = "Park"): | ^ *def [a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]* = •.+•\): *$ | |
Call this function. Don't override the defaults. | def x(y = "Bulgaria", z = 1.89): | x() | ^ *x\(\) *$ |
Code the first line of a function. It has one parameter without a default and a second parameter whose default is an integer. Make everything up. | def product_invoice(product_name, price = 1): | ^ *def [a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]* = -?[0-9]+\): *$ | |
Code the first line of a function. It has three parameters. All of them have defaults. The first parameter is the name of a list. The second parameter is a string. The third parameter is an integer. Make everything up. | def find_info(lst = customer_list, status = "premier", limit = 100): |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]* = •.+•, [a-zA-Z_][a-zA-Z0-9_]* = -?[0-9]+\): *$ | |
Code a call to this function that makes full_name equal "Hugo Jones". Don't pass any information to the function that you don't have to pass. | def assemble_name(last_name = "Jones", first_name = "John"): full_name = first_name + " " + last_name |
assemble_name(first_name = "Hugo") | ^ *assemble_name\(first_name = •Hugo•\) *$ |
|
766eff77e9 | ||
|
01cf4db075 |