Skip to content
Open

:D #14

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
26 changes: 23 additions & 3 deletions python/src/contacts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
def show_contacts(addressbook):
pass
print('Showing all contacts: ')
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):
pass
pattern = input('Enter a part of their name: ').strip()
for i, contact in enumerate(addressbook):
if pattern.lower() in contact["name"].lower():
print(f'{contact["name"]} has been deleted.')
addressbook.pop(i)
return
print('Contact not found')
32 changes: 30 additions & 2 deletions python/src/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
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():
print('[1] Display all contacts');
print('[2] Add a new contact');
print('[3] Delete a contact');
print('[4] Exit');
pass

def main():
pass
run = True
while run:
try:
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"Invalid selection: {selection}")
except ValueError:
print(f"Invalid integer input: {selection}")
continue
print('Goodbye.')

main()