What you'll build
Use a dictionary to remember five people and their phone numbers. Look one up, add one, loop over all of them.
Requirements
The must-do parts. If any are missing, we'll ask you to take another pass.
- Build a dictionary mapping at least five names to phone numbers.
- Print one contact by looking it up by name.
- Add a new contact and remove one. Show the dictionary before and after each change.
- Loop over the dictionary and print every contact as
Name — phone number.
Bonus, if you're feeling brave
- Convert your contacts into a list of dictionaries, where each contact has
name,phone, andarea. - Ask the user for a name and report whether they exist in your contacts.
Where to start
Copy this scaffold into a new file. You don't have to use it — it's just a friendly nudge.
contacts.py
contacts = {
"Adwoa": "0241112222",
"Kojo": "0553334444",
"Amara": "0245556666",
"Kwame": "0207778888",
"Yaa": "0269990000",
}
# TODO: print one contact by name
# TODO: add a new contact, then remove one, printing before and after
# TODO: loop over the contacts and print each as "Name — phone"How we'll grade it
Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.
| Check | What we look for | Pt |
|---|---|---|
| It runs | Clean run from top to bottom. | 1 |
| Dict basics | Builds, reads, and updates the dictionary correctly. | 1 |
| Loop reads well | The output of the loop is something a human can read. | 1 |
| Reflection | One short comment explaining when you'd pick a dict over a list. | 1 |