This is the Python version of the PhoneBook lab for beginner coders.
- Python 3.7 or higher
To run all tests:
python -m unittest discover -s . -p "test_*.py"To run a specific test file:
python -m unittest test_constructor.pyStudents need to implement the following methods in phonebook.py:
__init__()- Constructor that initializes the phonebook dictionaryadd()- Add a phone number for a contactadd_all()- Add multiple phone numbers for a contactremove()- Remove a contact from the phonebookhas_entry()- Check if a contact exists (with optional phone number check)lookup()- Look up all phone numbers for a contactreverse_lookup()- Find the contact name for a given phone numberget_all_contact_names()- Get all contact names in the phonebookget_map()- Get the underlying dictionary representation
test_constructor.py- Tests for constructor functionalitytest_add_all.py- Tests for adding multiple phone numberstest_get_all_contact_names.py- Tests for retrieving all contact namestest_remove.py- Tests for removing contactstest_reverse_lookup.py- Tests for reverse phone number lookup
The phonebook uses a dictionary where:
- Keys are contact names (strings)
- Values are lists of phone numbers (List[str])
Example:
{
"John": ["302-555-1234", "302-555-5678"],
"Jane": ["302-555-9999"]
}