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 assign pid4343's age to the variable. | age_of_patient = pid4343_____ | .age | ^ *\.age *$ |
Fill in the blank to assign sku_101's qty to the variable. | qty_on_hand = _____________ | sku_101.qty | ^ *sku_101\.qty *$ |
Get cushion's color. Assign it to the variable col_cushion. | col_cushion = cushion.color | col_cushion `= `cushion`.`color | |
Get the value of qty. Assign it to the variable on_hand. | sku_1212 = Product("premium", 144, "instock") | on_hand = sku_1212.qty | on_hand = sku_1212.qty |
In a single line of code display the value of an attribute for an instance. Make everything up. | print(patient0376.condition) | ^ *print\([a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*\) *$ | |
Assign the value of an attribute of an instance to a list element. Make everything up. | city_pops[16] = bangkok.population | ^ *[a-zA-Z_][a-zA-Z0-9_]*\[-?[0-9]+\] = [a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* *$ | |
Assign the value of an attribute of an instance to a dictionary item. The dictionary key is a string. Make everything up. | australian_cities["capital"] = australia.capital | ^ *[a-zA-Z_][a-zA-Z0-9_]*\[•.+•\] = [a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* *$ | |
If an attribute value of an instance equals another attribute value of that same instance, display a message. Make everything up. | if xyz.first_name == xyz.last_name: print("Weird!") |
^ *if ([a-zA-Z_][a-zA-Z0-9_]*)\.[a-zA-Z_][a-zA-Z0-9_]* == \1\.[a-zA-Z_][a-zA-Z0-9_]*:\n print\(•.+•\) *$ | |
An instance of this class has been created. Assign the value of one of its attributes to a variable. Make everything up, including the name of the instance. | def __init__(self, size, color, fabric): | material = sku2020.fabric | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\.(size|color|fabric) *$ |
Code a class that has just one attribute, an integer. Code an instance of the class. Then display the value of the instance's attribute. Make everything up. | class Student(): def __init__(self, age): self.age = age id4044 = Student(19) print(id4044.age) |
^ *class ([A-Z][a-zA-Z0-9_]*)\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\2 = \2\n([a-zA-Z_][a-zA-Z0-9_]*) = \1\([0-9]+\)\nprint\(\3\.\2\) *$ | |
|
59796c2784 | ||
|
fed9f70bf2 |