Skip to content

finishes deliverable #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions python/src/contacts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
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().lower()
idx = None
for i in range(len(addressbook)):
if pattern in addressbook[i]['name'].lower():
idx = i
if idx is None:
print(f'\nContact Not found!\n')
return
deleted_name = addressbook[idx]['name']
del addressbook[idx]
print(f'\n{deleted_name} was deleted.\n')


# def delete_contact(addressbook):
# pattern = input('Enter a part of their name: ').strip().lower()
# for contact in addressbook:
# if pattern in contact['name'].lower():
# addressbook.remove(contact)
# print(f'{contact["name"]} was deleted.')
# else:
# print('Contact Not found!')



25 changes: 22 additions & 3 deletions python/src/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import contacts

addressbook = []
addressbook = [
{ "name": 'Bruce Wayne', "phone": '555-123-4567', "email": '[email protected]' },
{ "name": 'Clark Kent',"phone": '555-222-3333', "email": '[email protected]' },
{ "name": 'Diana Prince', "phone": '555-444-5555', "email": '[email protected]' }
]

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(f'\nThat selection is not valid, please try again!\n')
print(f'\nGoodbye!\n')


main()