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
Change the last_name attribute of cust_20 to "Elb" | cust_20.last_name = "Elb" | ^ *cust_20\.last_name = •Elb• *$ | |
Change the population attribute of hexton to 123. | hexton.population = 123 | ^ *hexton\.population = 123 *$ | |
Change the last_name attribute of no444 to the value represented by new_last. | no444.last_name = new_last | no444`.`last_name `= `new_last | |
For the instance city33, call the method update, passing the argument 100. | city33.update(100) | city33.update(100) | |
Assign a new value, a string, to an attribute of an instance. Make everything up. | area51.slogan = "Don't ask" | ^ *[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* = •.+• *$ | |
Add together two of an instance's attributes and assign the result to a third attribute of the instance. Make everything up. | building15.total_area = building15.heated_area + building15.unheated_area | ^ *([a-zA-Z_][a-zA-Z0-9_]*)\.[a-zA-Z_][a-zA-Z0-9_]* = \1\.[a-zA-Z_][a-zA-Z0-9_]* \+ \1\.[a-zA-Z_][a-zA-Z0-9_]* *$ | |
Change the value of an attribute to a Boolean. Your choice of Boolean. Make up the name of the instance and the attribute name. | agent007.outmanned = True | ^ *[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* = True|False *$ | |
Change the value of an attribute to the result returned by a function. The function has no arguments. Make everything up. | screen7.now_playing = select_film() | ^ *[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\(\) *$ | |
Change the value of an attribute to the result returned by a method. Both the attribute and the method are in the same class. The method has no arguments. Make everything up. | factory20.output = factory20.double_output() | ^ *([a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*) = \1\.[a-zA-Z_][a-zA-Z0-9_]*\(\) *$ | |
Code a class that has one attribute and one method. The method has one parameter. The method changes the attribute to the sum of itself plus the parameter. Use shorthand for this (+=). Make everything up. | class Building(): def __init__(self, area): self.area = area def add(self, additional_area): self.area += additional_area |
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 = \1\n def [a-zA-Z_][a-zA-Z0-9_]*\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 \+= \2 *$ | |
|
752b8cb9b0 | ||
|
8c22bb577c |