All lessons

Functions & collections · step 18 of 22

Lab: the contact book

Sign in if you want this lab saved to your progress.

A dictionary plus a function

Build the smallest useful app: a phone book you can look names up in.

Build it yourself — nothing is given this time.

  1. contacts — a dictionary with these three entries, added in this order: Ada → 555-0101, Grace → 555-0102, Katherine → 555-0103
  2. a function lookup(name) that returns the phone number, or Unknown when the name is not in the book
  3. a loop that prints every contact, one per line, as Ada: 555-0101

Then print the result of lookup("Ada") and the result of lookup("Alan").

Build it

Fill in the code, then run it. Every check has to pass for the lab to count.

lab-contact-book.py