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
Condense this code to one line, using the function as a variable. | result = calc(20, 30) print(result) |
print(calc(20, 30)) | ^ *print\(calc\(20, 30\)\) *$ |
Condense this code to one line using the functions as variables. | first_result = calc(20, 30) second_result = calc(40, 50) total = first_result + second_result |
total = calc(20, 30) + calc(40, 50) | ^ *total = calc\(20, 30\) \+ calc\(40, 50\) *$ |
In a single line of code, concatenate the value returned by the function greet and the value returned by the function name. Assign the result to the variable whole_thing. | whole_thing = greet() + name() | whole_thing `= `greet`(`) `+ `name`(`) | |
Code the first line of an if statement that tests whether the value returned by the function calc is equal to 1. | if calc() == 1: | if calc() == 1: | |
Code a two-line function that returns the result of one function divided by another function. The functions have no arguments. Make everything up. | def calc(): return first_operation() / second_operation() |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n return [a-zA-Z_][a-zA-Z0-9_]*\(\) / [a-zA-Z_][a-zA-Z0-9_]*\(\) *$ | |
Call a function, assigning its returned value to a variable. The function's argument is another function with one positional argument, a string. Make everything up. | result = format(abbreviate("Laughing Out Loud")) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]*\(•.+•\)\) *$ | |
In a single line of code, do all this: Concatenate the value returned by one function and the value returned by another function. Assign the concatenated string to a variable. The functions have no arguments. Make everything up. | combo = generate_string_1() + generate_string_2() | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\(\) \+ [a-zA-Z_][a-zA-Z0-9_]*\(\) *$ | |
Code the first line of a for loop. It loops through the result returned by a function. Make everything up. | for each_element in create_list(): | ^ *for [a-zA-Z_][a-zA-Z0-9_]* in [a-zA-Z_][a-zA-Z0-9_]*\(\): *$ | |
Code a function that loops through a result returned by a function and appends each returned value to a list. The outer function has one positional parameter, the name of the list. Make everything up. | def add_to_list(customer_list): for a_customer in add_new_customers(): customer_list.append(a_customer) |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(([a-zA-Z_][a-zA-Z0-9_]*)\):\n for ([a-zA-Z_][a-zA-Z0-9_]*) in [a-zA-Z_][a-zA-Z0-9_]*\(\):\n \1\.append\(\2\) *$ | |
Code the first line of an if statement that tests whether the result returned by one function is the same as the result returned by another function. Both functions have keyword arguments whose values are variables. | if x(y=z) == a(b=c): | ^ *if [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_]*=[a-zA-Z_][a-zA-Z0-9_]*\): *$ | |
|
83bf3ac931 | ||
|
49ed293b35 |