Python Essentials 1
Overview
You will develop a simple Contact Book console application. This project integrates topics from Modules 1-4, including input/output, data types, conditionals, loops, functions, data structures (lists/dictionaries), and exception handling. The Contact Book allows a user to store, view, search, and delete contact entries. Each contact will have a name and phone number (you can also include email or address optionally). The program will provide a menu for the user to choose actions.
Requirements
Your Contact Book application should support the following features:
- Add a New Contact: Prompt the user for a name and phone number. Store this contact in the contact list (or dictionary). Ensure that a name can only exist once (if the user tries to add a name that already exists, print a message and do not duplicate the entry).
- View All Contacts: Display a list of all contacts currently stored, showing each contact’s name and phone number. If there are no contacts, print a message saying the contact list is empty.
- Search for a Contact: Ask the user for a name (or part of a name) to search. Display any contacts that match (this can be an exact match or, for an extra challenge, allow partial matches). If no match is found, inform the user.
- Delete a Contact: Ask the user for the name of the contact to delete. If the contact exists, remove it from the list and confirm deletion. If it doesn’t exist, print a message stating so.
- Exit: Exit the program.
The program should use a loop to show the menu after each action (except exit). The menu can be text-based, for example:
Contact Book Menu:
1. Add New Contact
2. View All Contacts
3. Search Contact
4. Delete Contact
5. Exit
Enter your choice (1-5):
Important implementation details:
- Use a dictionary to store contacts, where the key is the contact name and the value is the phone number (this ensures names are unique and allows efficient lookup for search/delete).
- Implement each feature in a separate function (e.g.,
add_contact
,view_contacts
,search_contact
,delete_contact
) to practice function design. You can have these functions take the contacts dictionary as a parameter and modify it as needed. - Include input validation: if the user enters an invalid menu choice (not 1-5), display an error and show the menu again. For adding contacts, ensure phone number input is reasonable (for simplicity, you can decide what constitutes a valid phone number, e.g., contains only digits or certain length).
- Use try/except blocks where appropriate, for example to catch unexpected errors or handle cases like converting input to an integer for the menu choice.
Optional enhancements (for extra credit or practice):
- Allow multiple phone numbers per contact (using a list for each entry’s phone numbers).
- Save contacts to a file and load them on program start (requires file I/O, which is beyond the core scope of Modules 1-4, so only attempt if you’re comfortable).
- Implement sorting when viewing contacts (e.g., display in alphabetical order by name).
Submission for Project
Submit the following via a link to a single GitHub repository containing all the files:
- Your code file, e.g.,
contact_book.py
. - Example interaction logs: copy and paste the console output from a test run of your program demonstrating:
- Adding at least two contacts (including one duplicate attempt to show how it’s handled).
- Viewing contacts.
- Searching for a contact (one successful search and one unsuccessful search).
- Deleting a contact.
- Exiting the program.
- A brief write-up (can be comments in the code or a separate document) explaining how you structured your program (what functions you used, how data flows, any challenges faced and how you solved them).
Make sure to double-check that your project runs without errors and your quiz answers are clearly indicated. Good luck, and congratulations on completing Python Essentials 1!
Grading Rubric for Project
The total points for this project is 100 points.
Below is the rubric reformatted as a table and scaled to a total of 100 points:
Criteria | Points | Description |
---|---|---|
Functionality (55 pts total) | ||
- Add Contact works | 9 | Correctly adds new contacts and handles duplicates. |
- View Contacts works | 9 | Correctly displays all contacts or an appropriate message if none exist. |
- Search Contact works | 9 | Finds existing contacts or reports none found. |
- Delete Contact works | 9 | Removes a contact if present or reports if not found. |
- Menu Loop and Exit | 9 | The menu repeats after operations and the program exits gracefully when chosen. |
- Data Handling | 10 | Uses appropriate data structures (e.g., dictionary for contacts) and maintains data integrity (e.g., prevents duplicate names). |
Code Design (18 pts total) | ||
- Uses functions to organize code | 9 | Organizes code into distinct functions for add, view, search, and delete features. |
- Code reusability and modularity | 9 | Avoids repeating code by effectively using functions and loops. |
User Input Handling and Validation (9 pts total) | ||
- Menu input validation | 4 | Validates menu input (e.g., when the user enters a number outside 1–5) without crashing. |
- Input validation for adding contacts | 5 | Validates inputs for adding contacts (e.g., checking phone number format or handling empty name input). |
Use of Concepts (9 pts total) | ||
- Demonstrates use of conditionals | 2 | Utilizes if/else statements for menu choices and input checks. |
- Demonstrates use of loops | 2 | Employs loops (while loop for the menu, for loop in search, etc.) effectively. |
- Utilizes data structures | 2 | Uses appropriate data structures (e.g., dictionary for contacts, lists if needed) to store and manage data. |
- Implements try/except for error handling | 1 | Uses try/except to handle errors (such as input conversion issues or file I/O errors) gracefully. |
- Uses functions and return values appropriately | 2 | Effectively uses functions to encapsulate operations and returns values as needed. |
Code Quality and Documentation (9 pts total) | ||
- Code is well-formatted | 4 | Code follows proper indentation and naming conventions. |
- Comments are present | 4 | Key sections and tricky parts (e.g., function descriptions) are clearly commented. |
- Meaningful variable and function names | 1 | Variable and function names clearly convey their purpose. |
Partial credit will be awarded for incomplete functionality if substantial effort is shown. For example, if all features are implemented but search is case-sensitive or only exact match, that is okay (minor deduction at most). If the program works but is not organized into functions, it will lose design points but still get points for functionality. The goal is a working program demonstrating course concepts, so even if you encounter challenges, document them and submit what you have for partial credit.