Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Welcome to your first end-to-end Python capstone project! Up to this point, you have mastered variables, strings, data structures (lists, tuples, sets, dictionaries), conditionals, loops, functions, and file handling.
In this project, you will integrate all these concepts into a production-grade Command-Line Contact Book Application featuring full CRUD (Create, Read, Update, Delete) operations, Indian mobile number validation, and deterministic disk persistence using the context manager.
In Indian homes before smartphones, every family kept a spiral-bound telephone diary beside the landline phone:
+-------------------------------------------------------------------------+ | INDIAN HOUSEHOLD TELEPHONE DIARY ARCHITECTURE | +-------------------------------------------------------------------------+ | | | [ CLI Menu Interface ] | | │ | | ▼ | | [ Input Validation Layer ] ──> Validates 10-digit Indian Mobile & Email| | │ | | ▼ | | [ In-Memory Hash Map (Dict) ] ──> Fast O(1) Search, Add, Update, Delete| | │ | | Save │ ▲ Load at Startup | | ▼ │ | | [ Storage Engine: contacts.txt via 'with open()' Context Manager ] | | | +-------------------------------------------------------------------------+
contacts.txt read into RAM).Our Contact Book requires the following specifications:
contacts_db.txt) using the format:Name|Phone|Email|Category\n
@ and a period . after @.while True loop with interactive options 1 to 6.Here is the complete, modular, runnable code for the entire Contact Book system:
How data and code flow step-by-step
| Practice | Bad Implementation | Gold-Standard Implementation | |
|---|---|---|---|
| Lookup Keys | Using case-sensitive keys ("Rahul" vs "rahul") | Normalize keys with .strip().lower() | |
| Input Validation | Trusting user input blindly without checks | Validate 10-digit format and email structure before saving | |
| Persistence | Keeping contacts purely in RAM (lost on crash) | Persist every mutation to disk using with open() | |
| Data Format | Unstructured arbitrary string writes | Consistent structured delimiter (`\ | ` or CSV/JSON) |
| Search | Exact match only | Substring search across both name and phone fields | |
| Deletion | Crashing with KeyError if name is missing | Verify key existence with if key in contacts: |
contacts[normalized_key] = {...}display_all() and search_contacts()del contacts[key] with prior key existence check.name.strip().lower() for dictionary keys so queries like "AMIT", "amit", and " Amit " match seamlessly.save_contacts() immediately after any mutating operation (add, update, delete).try...except ValueError to prevent sudden crashes.FileNotFoundError when initializing terminal databases.load_data(), save_data(), display_menu(), add_record()).Enhance the Contact Book with two features:
is_favorite boolean field to each contact (defaulting to False).toggle_favorite(contacts, name) that flips the boolean status and saves to disk.get_favorites(contacts) that returns only VIP contacts.export_to_csv(contacts, filename) that writes the contacts with a standard CSV header: Name,Phone,Email,Category,Favorite.In the next lesson, we will continue your Python learning journey with Quiz Application (16: Projects).
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| File Methods (read, readline, write) | Quiz Application |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.