An object-oriented contact book that lets you add, search, edit, and delete contacts from the command line. Contacts are stored in a JSON file so they persist between sessions.
- Classes and OOP (Contact class, ContactBook class)
- File I/O with JSON
- Error handling
- Searching and filtering
- Input validation
- Text-based menu interfaces
- Add a contact (name, phone, email)
- List all contacts
- Search contacts by name (partial match)
- Delete a contact by name
- Save/load contacts to/from a JSON file
- Edit an existing contact's details
- Add multiple phone numbers or emails per contact
- Sort contacts by name
- Export contacts to CSV
- Add categories/tags to contacts
- Input validation for phone numbers and email format
=== Contact Book ===
1. Add contact
2. List contacts
3. Search contacts
4. Delete contact
5. Quit
Choose an option: 1
Name: Alice Smith
Phone: 555-1234
Email: alice@example.com
Contact added!
Choose an option: 1
Name: Bob Jones
Phone: 555-5678
Email: bob@example.com
Contact added!
Choose an option: 3
Search: ali
Found 1 contact(s):
Alice Smith | 555-1234 | alice@example.com
Choose an option: 2
All contacts:
1. Alice Smith | 555-1234 | alice@example.com
2. Bob Jones | 555-5678 | bob@example.com
Choose an option: 5
Contacts saved. Goodbye!
- Create a
Contactclass withname,phone,emailattributes and ato_dict()method - Create a
ContactBookclass that holds a list ofContactobjects and handles load/save - Use
json.dump()/json.load()with[contact.to_dict() for contact in contacts] - For search, use
if query.lower() in contact.name.lower()for case-insensitive partial matching - Use a
while Trueloop for the menu, withbreakwhen the user chooses quit - A
@classmethodcalledfrom_dict()is a clean way to recreate Contact objects from JSON
starter.py— skeleton code with class and method signaturessolution.py— complete working implementation