diff --git a/js/src/contacts.js b/js/src/contacts.js index 78fbcc4..e1edc7c 100644 --- a/js/src/contacts.js +++ b/js/src/contacts.js @@ -16,7 +16,7 @@ function addContact(addressbook) { const newContact = { name: name, - phone: phone, + phoncone: phone, email: email }; addressbook.push(newContact); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..656240d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "M4L3-python-containers-wbp", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/python/src/contacts.py b/python/src/contacts.py index 4dce478..86a6d76 100644 --- a/python/src/contacts.py +++ b/python/src/contacts.py @@ -1,8 +1,37 @@ 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() + + new_contact = { + "name": name, + "phone": phone, + "email": email + } + addressbook.append(new_contact) + + print(f'\n{name} was added.\n') def delete_contact(addressbook): + pattern = input('Enter a part of their name: ').strip() + + idx = None + for i in range(len(addressbook)): + if addressbook[i]['name'].index(pattern) >= 0: + idx = i + + if idx == None: + print('\nContact Not found!\n') + return + + deleted_name = addressbook[idx]['name'] + addressbook.pop(idx) + + print(f"\n{deleted_name} was deleted.\n") pass diff --git a/python/src/main.py b/python/src/main.py index 7bd07c8..5f12334 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,11 +1,36 @@ 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: ')) + + match selection: + case 1: + contacts.show_contacts(addressbook) + case 2: + contacts.add_contact(addressbook) + case 3: + contacts.delete_contact(addressbook) + case 4: + run = False + case _: print('\nThat selection is not valid, please try again!\n') + + + + print('\nGoodbye!\n') main()