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
Code an empty list. Make up the list name. | products = [] | ^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\] *$ | |
Code an empty dictionary. Make up the dictionary name. | statistics = {} | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {} *$ | |
The dictionary name is ranks. Add an item to it. The key is 10. The value is "Spain". | ranks[10] = "Spain" | ranks`[`10`] `= `"`Spain`" | |
The dictionary name is products. Add an item to it. The key is "laptop". The value is 397.50. | products["laptop"] = 397.50 | products["laptop"] = 397.50 | |
Add a string element to a list, using the plus sign. Make up the string and the list name. | products = products + ["laptop"] | ^ *([a-zA-Z_][a-zA-Z0-9_]*) = \1 \+ \[•.*•\] *$ | |
Add an item to a dictionary. The key is a number. The value is a string. Make everything up. | ranks[10] = "Spain" | ^ *[a-zA-Z_][a-zA-Z0-9_]*\[[-]?(?:[.]\d+|\d+(?:[.]\d*)?)\] = •.*• *$ | |
Add two elements to a list using the plus sign. The elements are numbers. Make everything up. | num_list = num_list + [92, 144] | ^ *([a-zA-Z_][a-zA-Z0-9_]*) = \1 \+ \[[-]?(?:[.]\d+|\d+(?:[.]\d*)?), [-]?(?:[.]\d+|\d+(?:[.]\d*)?)\] *$ | |
Add two items to a dictionary. All keys and values are strings. Make everything up. | pets["cat"] = "Rover" pets["dog"] = "Fluffy" | ^ *([a-zA-Z_][a-zA-Z0-9_]*)\[•.*•\] = •.*•\n\1\[•.*•\] = •.*• *$ | |
Add a string to the end of a list using the append keyword. Make up the list name and the string. | a_list.append("boing") | ^ *[a-zA-Z_][a-zA-Z0-9_]*\.append\(•.*•\) *$ | |
Add two items to a dictionary. Keys and values can be any combination of strings and numbers. Make everything up. | strange_dictionary["first thing"] = 100 strange_dictionary[1] = "last thing" | ^ *([a-zA-Z_][a-zA-Z0-9_]*)(\[•.+•\]|\[[0-9]+\]) = (•.+•|[0-9]+)\n\1(\[•.+•\]|\[[0-9]+\]) = (•.+•|[0-9]+) *$ | |
| 19cc72da07 | ||
| f96a0f9d97 |