diff --git a/python/src/contacts.py b/python/src/contacts.py deleted file mode 100644 index 4dce478..0000000 --- a/python/src/contacts.py +++ /dev/null @@ -1,8 +0,0 @@ -def show_contacts(addressbook): - pass - -def add_contact(addressbook): - pass - -def delete_contact(addressbook): - pass diff --git a/python/src/contacts/__init__.py b/python/src/contacts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/src/contacts/contacts.py b/python/src/contacts/contacts.py new file mode 100644 index 0000000..3868f66 --- /dev/null +++ b/python/src/contacts/contacts.py @@ -0,0 +1,22 @@ +def show_contacts(address_book): + print("\nContacts:\n") + for contact in address_book: + print(f"{contact['name']} {contact['email']} : {contact['phone']}") + + +def add_contact(address_book): + new_contact = {} + print("\nAdding a contact\n") + for s in ["name", "phone", "email"]: + new_contact[s] = input(f"Enter {s}: ") + address_book.append(new_contact) + + +def delete_contact(address_book): + print("\nDeleting one or more contacts\n") + partial = input("Enter a part of their name: ").lower() + print(f"Deleting contacts with name matching {partial}") + for ndx, contact in enumerate(address_book): + if partial in contact["name"].lower(): + print(f"Deleting {contact['name']}") + address_book.pop(ndx) diff --git a/python/src/main.py b/python/src/main.py index 7bd07c8..465f485 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,11 +1,38 @@ -import contacts +import contacts.contacts -addressbook = [] +address_book = [ + {"name": "Bruce Wayne", "phone": "555-123-4567", "email": "bruce@wayne.com"}, + {"name": "Clark Kent", "phone": "555-222-3333", "email": "clark@dailyplanet.com"}, + {"name": "Diana Prince", "phone": "555-444-5555", "email": "diana@amazon.com"}, +] +menus = [ + "[1] Display all contacts", + "[2] Add a new contact", + "[3] Delete a contact", + "[4] Exit", +] -def menu(): - pass -def main(): - pass +def main(address_book): + selection = "" + while selection != "4": + for menu in menus: + print(menu) + selection = input("Enter a selection: ") + match selection: + case "1": + contacts.contacts.show_contacts(address_book) + case "2": + contacts.contacts.add_contact(address_book) + case "3": + contacts.contacts.delete_contact(address_book) + case "4": + print("Goodbye!") + case "5": + contacts.contacts.delete_proper(address_book) + case _: + print("That selection is not valid, please try again!") + print("") -main() + +main(address_book)