From 31aa35e9a12fd2b182e84913f61d96b6ed4fa9bc Mon Sep 17 00:00:00 2001 From: mHaines331 Date: Mon, 4 Dec 2023 16:47:14 -0800 Subject: [PATCH 1/3] add contacts --- python/src/contacts.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/python/src/contacts.py b/python/src/contacts.py index 4dce478..8748c91 100644 --- a/python/src/contacts.py +++ b/python/src/contacts.py @@ -1,8 +1,22 @@ def show_contacts(addressbook): - pass + pass + def add_contact(addressbook): - pass + name = input("Enter name: ") + phone = input("Enter phone: ") + email = input("Email: ") + + new_contact = { + "name": name.strip(), + "phone": phone.strip(), + "email": email.strip(), + } + + addressbook.append(new_contact) + + console.log(f"{new_contact[name]} was added") + def delete_contact(addressbook): - pass + pass From b3f884ca0ac39a670b47698ced8077531b41c066 Mon Sep 17 00:00:00 2001 From: mHaines331 Date: Mon, 4 Dec 2023 16:48:15 -0800 Subject: [PATCH 2/3] add contact --- python/src/contacts.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/python/src/contacts.py b/python/src/contacts.py index 8748c91..0fe56a4 100644 --- a/python/src/contacts.py +++ b/python/src/contacts.py @@ -2,21 +2,7 @@ def show_contacts(addressbook): pass -def add_contact(addressbook): - name = input("Enter name: ") - phone = input("Enter phone: ") - email = input("Email: ") - - new_contact = { - "name": name.strip(), - "phone": phone.strip(), - "email": email.strip(), - } - - addressbook.append(new_contact) - - console.log(f"{new_contact[name]} was added") - +g def delete_contact(addressbook): pass From a3149a33d992f5d60e2da93d4a16e81572c336ef Mon Sep 17 00:00:00 2001 From: mHaines331 Date: Thu, 7 Dec 2023 17:20:06 -0800 Subject: [PATCH 3/3] wbp pass --- python/src/contacts.py | 36 +++++++++++++++++++++++++++++++++--- python/src/main.py | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/python/src/contacts.py b/python/src/contacts.py index 0fe56a4..b76e951 100644 --- a/python/src/contacts.py +++ b/python/src/contacts.py @@ -1,8 +1,38 @@ def show_contacts(addressbook): - pass + print(None) + for contact in addressbook: + print(f"{contact['name']} ({contact['email']}): {contact['phone']}") + print(None) -g +def add_contact(addressbook): + name = input("Enter name: ") + phone = input("Enter phone: ") + email = input("Email: ") + + new_contact = { + "name": name.strip(), + "phone": phone.strip(), + "email": email.strip(), + } + + addressbook.append(new_contact) + + print(f"\n{new_contact['name']} was added.\n") + def delete_contact(addressbook): - pass + pattern = input("Enter a part of their name: ").strip() + idx = None + for i, contact in enumerate(addressbook): + if contact["name"].find(pattern) != -1: + idx = i + break + + if idx is None: + print("\nContact Not found!\n") + return + deleted_name = addressbook[idx]["name"] + del addressbook[idx] + + print(f"\n{deleted_name} was deleted.\n") diff --git a/python/src/main.py b/python/src/main.py index 7bd07c8..308b092 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,11 +1,38 @@ import contacts -addressbook = [] +addressbook = [ + {"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"}, +] + def menu(): - pass + print("[1] Display all contacts") + print("[2] Add a new contact") + print("[3] Delete a contact") + print("[4] Exit") + def main(): - pass + run = True + while run: + menu() + selection = int(input("Enter a selection: ")) + if selection == 1: + contacts.show_contacts(addressbook) + + elif selection == 2: + contacts.add_contact(addressbook) + + elif selection == 3: + contacts.delete_contact(addressbook) + + elif selection == 4: + run = False + else: + print("\nThat selection is not valid, please try again!\n") + print("\nGoodbye!\n") + main()