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
A key can be a string. It can also be a _________. | number | ^ *number *$ | |
A value paired with a key can be a number. It can also be a _________. | string | ^ *string *$ | |
The dictionary has just one item. The dictionary's name is products. The key is 101. The value is "wrench." Code the dictionary. | products = {101: "wrench"} | products `= `{`101`: `"`wrench`"`} | |
The dictionary has just one item. The dictionary's name is x. The key is "A12". The value is 9.99 Code the dictionary. | x = {"A12": 9.99} | x = {"A12": 9.99} | |
Code a dictionary with a single item. Both the key and the value are numbers. Make everything up. | square_roots = {144: 12} | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {[-]?(?:[.]\d+|\d+(?:[.]\d*)?): [-]?(?:[.]\d+|\d+(?:[.]\d*)?)} *$ | |
Code a dictionary with a single item. Both the key and the value are strings. Make everything up. | bodies_of_water = {"ocean": "Pacific"} | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {•.*•: •.*•} *$ | |
Code a one-item dictionary. The key is a number. The value is a string. Make everything up. | products = {133: "smart phone"} | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {[-]?(?:[.]\d+|\d+(?:[.]\d*)?): •.+•} *$ | |
Code a one-item dictionary. The key is a string. The value is a number. Make everything up. | sizes = {"omelet pan": 10} | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {•.*•: [-]?(?:[.]\d+|\d+(?:[.]\d*)?)} *$ | |
Code a two-item dictionary, breaking the code into four lines. All keys and values are strings. Don't forget to indent properly. Don't forget the optional comma after the second item. Make everything up. | equivalences = { "foot": "12 inches", "yard": "3 feet", } | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {\n •.*•: •.*•,\n •.*•: •.*•,\n} *$ | |
Code a three-item dictionary, breaking the code into five lines. All keys are numbers. All values are strings. Make everything up. | numerals_and_words = { 1: "one", 2: "two", 3: "three", } | ^ *[a-zA-Z_][a-zA-Z0-9_]* = {\n [-]?(?:[.]\d+|\d+(?:[.]\d*)?): •.*•,\n [-]?(?:[.]\d+|\d+(?:[.]\d*)?): •.*•,\n [-]?(?:[.]\d+|\d+(?:[.]\d*)?): •.*•,\n} *$ | |
| 734d418c8c | ||
| 14447d3eab |