Python Series track

Project 7 · Practice Projects

Project 7 — Contacts Manager

Build an object-oriented contacts manager with name, phone, email, and tags. Support search, sort, and CSV/JSON export.

Practice Projects1 min readFree lesson

Difficulty: Lv ★★ | Prerequisite Knowledge: Basic weeks 7-8

Goal

Search, modify, delete name·phone·email (partial match)

Requirements

  • Data: {"Name": {"phone": "...", "email": "..."}}
  • Commands: add, find <keyword>, update, del, list
  • Partial match search

Challenge Task

  • Handling same names (automatic number)
  • Phone number format validation

Assignment

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

solution.pyPython
"""Address Book — Partial Match Search"""

contacts = {}

def add():
    name = input("Name:").strip()
    if not name: return
    phone = input("Phone:").strip()
    email = input("Email:").strip()
    contacts[name] = {"phone": phone, "email": email}
    print("Added")

def find(query):
    matched = [(n, c) for n, c in contacts.items() if query.lower() in n.lower()]
    if not matched:
        print("None"); return
    for name, c in matched:
        print(f"  {name} | {c['phone']} | {c['email']}")

def show_all():
    for name in sorted(contacts):
        c = contacts[name]
        print(f"  {name}: {c['phone']}, {c['email']}")

def main():
    while True:
        raw = input("Command (add/find <q>/del <name>/list/quit):").strip()
        if not raw: continue
        parts = raw.split(maxsplit=1)
        cmd = parts[0]
        arg = parts[1] if len(parts) > 1 else ""
        if cmd == "quit": break
        elif cmd == "add": add()
        elif cmd == "find":
            if arg: find(arg)
            else: print("Enter keyword")
        elif cmd == "del":
            if arg in contacts:
                del contacts[arg]; print("Delete")
            else:
                print("None")
        elif cmd == "list":
            show_all()

if __name__ == "__main__":
    main()

Learn this lesson with a mentor

Work through the Python Series track on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now