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
To find how many dictionaries are in the customers list and load the number into the variable, complete the line. | num_of_dicts = ____________ | len(customers) | ^ *len\(customers\) *$ |
Measure the number of dictionaries in a list and load the number into a variable. Make everything up. | num_of_dicts = len(customers) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = len\([a-zA-Z_][a-zA-Z0-9_]*\) *$ | |
We're adding a new dictionary to a list of dictionaries. The index number of the new dictionary will be the same as the ________ of the list before we add the new dictionary. | length | length | |
The length (number of dictionaries) of the customers list will be both the index number and the customer id of the new dictionary. Code the line that finds the length of the customers list and assigns it to the variable new_customer_id. | new_customer_id = len(customers) | new_customer_id = len(customers) | |
Find the length of a list and assign it to a variable. Make everything up. | new_customer_id = len(customers) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = len\([a-zA-Z_][a-zA-Z0-9_]*\) *$ | |
We're creating the new dictionary to add to the list customers. The first key-value pair is "id" and the value stored in new_customer_id. Code the next line. Remember to indent it and add a comma at the end. | new_dictionary = { | "id": new_customer_id, | ^ * •id•: new_customer_id, *$ |
Code the next key-value pair in the new dictionary. The key is "last name". The value is stored in the variable new_last_name. Remember to indent the line and end the line with a comma. | new_dictionary = { "id": new_customer_id, |
"last name": new_last_name, | ^ * •last name•: new_last_name, *$ |
The last pair in the dictionary is "first name" and the value stored in new_first_name. Code the line. Remember to indent and to end the line with a comma. | new_dictionary = { "id": new_customer_id, "last name": new_last_name, |
"first name": new_first_name, | ^ * •first name•: new_first_name, *$ |
All the pairs in the dictionary are now defined. Complete the definition of the new dictionary. | new_dictionary = { "id": new_customer_id, "last name": new_last_name, "first name": new_first_name, |
} | ^ *} *$ |
You've defined a new dictionary and assigned it to the variable new_dictionary. Now append it to the customers list. | customers.append(new_dictionary) | ^ *customers\.append\(new_dictionary\) *$ | |
|
5ba0c4c492 | ||
|
30fb8f1374 |