wk02.p2Practice exerciseWeek 02 · Organizing dataOpen · due in week 2

Mini contacts book

Use a dictionary to remember five people and their phone numbers. Look one up, add one, loop over all of them.

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.

  1. Build a dictionary mapping at least five names to phone numbers.
  2. Print one contact by looking it up by name.
  3. Add a new contact and remove one. Show the dictionary before and after each change.
  4. 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, and area.
  • 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.

CheckWhat we look forPt
It runsClean run from top to bottom.1
Dict basicsBuilds, reads, and updates the dictionary correctly.1
Loop reads wellThe output of the loop is something a human can read.1
ReflectionOne short comment explaining when you'd pick a dict over a list.1
Ready?
Hand it in
You can submit a draft and revise later if you're not done.
Begin submission →