Projects · 4 / 19 Exercise Medium

Contact book project

Objective

Create a Python program that manages a contact book stored in a dictionary (name → phone). It is the first mini-project: organise the code in functions and a main loop that reads commands.

Instructions

  • Read an integer n and then n commands, one per line. Names and phone numbers contain no spaces.
  • add NAME PHONE: stores the contact. Show Added: NAME if it is new or Updated: NAME if it already existed (the phone is replaced).
  • find NAME: show NAME: PHONE, or Not found: NAME if it does not exist.
  • delete NAME: remove the contact and show Deleted: NAME, or Not found: NAME if it does not exist.
  • list: show one NAME: PHONE line per contact, sorted by name, or Empty contact book if the book is empty.
  • At the end, show Contacts: K with the number of contacts left.
Input
5
add Ana 600111222
add Luis 600333444
find Ana
delete Luis
list
Output
Added: Ana
Added: Luis
Ana: 600111222
Deleted: Luis
Ana: 600111222
Contacts: 1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise