Description
Part A
We would like to make some changes to a customer’s information.
1. Copy and paste this line of code to your script:
customer = {‘name’: ‘Orwell’, ‘address’:’4 Church St’, ‘age’:’46’}
Note: do not make changes to this line;
2. Using the dictionary from step 1, write code that will perform the following actions:
a. Find and print the customer’s address;
b. Add a new key-value to the dictionary:
i. the key will be ‘birthday’ and its value will be ’25 June’;
c. Change the value associated with ‘name’ to ‘Orwell, George’;
d. Finally, print the customer variable to show those changes have been made.
Part A Example output:
4 Church St
{‘name’: ‘Orwell, George’, ‘address’: ‘4 Church St’, ‘age’: ’46’, ‘birthday’: ’25 June’}
Part A Extra challenge:
Can you make the changes to Orwell’s record if the dictionary in step 1 looked like this:
customer = {1:{‘name’: ‘Orwell’, ‘address’:’4 Church St’, ‘age’:’46’}
, 2:{‘name’: ‘Cicero’, ‘address’:’11 Carmine St’, ‘age’:’63’}}
Part A Extra Challenge Example:
4 Church St
{1: {‘name’: ‘Orwell, George’, ‘address’: ‘4 Church St’, ‘age’: ’46’, ‘birthday’: ’25 June’}, 2: {‘name’: ‘Cicero’,
‘address’: ’11 Carmine St’, ‘age’: ’63’}}
Part B
We would like to make some adjustments to a phonebook stored in a dictionary. You must:
1. Copy and paste this dictionary:
phonebook = {
‘Euclid’: {‘number’:’212.479.2851′}
, ‘Pythagoras’: {‘number’:’212.479.4953′}
, ‘Avicenna’: {‘number’:’212.892.1234′}
, ‘Descartes’: {‘number’:’917.372.1650′}
}
Note: Do not edit this dictionary. It should appear at the top of Part B exactly as it is here.
The following requirements must be met using code (you cannot just manually retype the
dictionary).
2. Use the get function to search for Newton in the phonebook. If Newton is in the phonebook,
the value associated with his name should be printed. If he is not, ‘Name not found’ should
be printed.
3. Using what is returned by the get function in step 2, write an if statement that will add
Newton to the phonebook if he is not currently in there. His number is 917.364.1727.
4. Change Avicenna’s phone number to 212.472.1037.
5. Remove Descartes from the phonebook.
6. Using a for loop, print each name and number so it appears in this format:
Euclid 212.479.2851
Pythagoras 212.479.4953
Avicenna 212.472.1037
Newton 917.364.1727
Note: it does not need to be in the same order.
Part B Example:
Name not found
Euclid 212.479.2851
Pythagoras 212.479.4953
Avicenna 212.472.1037
Newton 917.364.1727
Part B Extra challenge
1. Using a for loop, can you add the area code for each person to the phonebook? The area code is
the first 3 numbers in the phone number. After you are done, print the phonebook. It should
look like this:
{‘Euclid’: {‘number’: ‘212.479.2851’, ‘areaCode’: ‘212’}
, ‘Pythagoras’: {‘number’: ‘212.479.4953’, ‘areaCode’: ‘212’}
, ‘Avicenna’: {‘number’: ‘212.472.1037’, ‘areaCode’: ‘212’}
, ‘Newton’: {‘number’: ‘917.364.1727’, ‘areaCode’: ‘917’}}
Note: it does not need to be in the same order.
2. Can you conduct a reverse lookup? That is, can you search the phonebook for the value
‘212.479.4953’. If it is found, the name associated with this number should be printed. The
output should look like this:
The name associated with 212.479.4953 is: Pythagoras

