From 08dc2a839b908b15c6976f19063638f894b118ba Mon Sep 17 00:00:00 2001 From: kfac Date: Tue, 5 Dec 2023 21:18:07 -0600 Subject: [PATCH 1/2] menu and main work but do not call contact --- python/src/main.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/python/src/main.py b/python/src/main.py index 7bd07c8..a66881f 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,11 +1,40 @@ 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: + print('\nYou have selected option 1\n') + #contacts.showContacts(addressbook) + # break + elif selection == 2: + print('\nYou have selected option 2\n') + #contacts.addContact(addressbook) + # break + elif selection == 3: + print('\nYou have selected option 3\n') + #contacts.deleteContact(addressbook) + # break + elif selection == 4: + run = False + # break + else: + print('\nThat selection is not valid, please try again!\n') + + print('\nGoodbye!\n') main() From dcb1f90e527fb11f345b1191b0c2cc74861ef488 Mon Sep 17 00:00:00 2001 From: kfac Date: Tue, 5 Dec 2023 22:58:35 -0600 Subject: [PATCH 2/2] contacts works and it conneted to main --- python/src/contacts.py | 32 +++++++++++++++++++++++++++++--- python/src/main.py | 20 ++++++++++---------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/python/src/contacts.py b/python/src/contacts.py index 4dce478..530e194 100644 --- a/python/src/contacts.py +++ b/python/src/contacts.py @@ -1,8 +1,34 @@ def show_contacts(addressbook): - pass + print() + for contact in addressbook: + print(f"{contact['name']} ({contact['email']}): {contact['phone']}") + print() def add_contact(addressbook): - pass + name = input('Enter name: ').strip() + phone = input('Enter phone: ').strip() + email = input('Enter email: ').strip() + newContact = { + 'name': name, + 'phone': phone, + 'email': email + } + addressbook.append(newContact) + print(f'\n{name} was added.\n') def delete_contact(addressbook): - pass + pattern = input('Enter a part of their name: ').strip() + idx = None + + for contact in addressbook: + if contact['name'].find(pattern) >= 0: + idx = addressbook.index(contact) + + if idx == None: + print('\nContact Not found!\n') + return + + deletedName = addressbook[idx]['name'] + addressbook.pop(idx) + + print(f'\n{deletedName} was deleted.\n') \ No newline at end of file diff --git a/python/src/main.py b/python/src/main.py index a66881f..869f1aa 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -18,20 +18,20 @@ def main(): menu() selection = int(input('Enter a selection: ')) if selection == 1: - print('\nYou have selected option 1\n') - #contacts.showContacts(addressbook) - # break + # print('\nYou have selected option 1\n') + contacts.show_contacts(addressbook) + break elif selection == 2: - print('\nYou have selected option 2\n') - #contacts.addContact(addressbook) - # break + # print('\nYou have selected option 2\n') + contacts.add_contact(addressbook) + break elif selection == 3: - print('\nYou have selected option 3\n') - #contacts.deleteContact(addressbook) - # break + # print('\nYou have selected option 3\n') + contacts.delete_contact(addressbook) + break elif selection == 4: run = False - # break + break else: print('\nThat selection is not valid, please try again!\n')