Skip to content
Snippets Groups Projects
Commit 21979e02 authored by Jöran Frey's avatar Jöran Frey
Browse files

added exercise

parent 1f888602
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Extra Exercises
%% Cell type:markdown id: tags:
## Build a Contact Manager
Write a Python program that manages a list of contacts. Programm functions that allow a User to add, search, delete, and display contacts.
```Hint```: the basic framework is already there, you just have to programme the functions
%% Cell type:code id: tags:
``` python
# Contact Manager Program
# List to store contacts with some examples
contacts = [ {"name": "Alice Johnson", "phone": "1234567890", "email": "alice@example.com"},
{"name": "Bob Smith", "phone": "9876543210", "email": "bob.smith@example.com"},
{"name": "Charlie Brown", "phone": "5556667777", "email": "charlie.brown@example.com"},
{"name": "John Do", "phone": "1112223333", "email": "diana.prince@example.com"}]
def display_menu():
"""Displays the menu."""
print("\nContact Manager")
print("1. Add Contact")
print("2. Search Contact")
print("3. Update Contact")
print("4. Delete Contact")
print("5. Display All Contacts")
print("6. Exit")
def add_contact():
print("you chose 1. Add Contact")
def search_contact():
print("you chose 2. Search Contact")
"""Searches for a contact by name."""
def delete_contact():
print("you chose 3. delete a contact")
"""Deletes a contact."""
def display_all_contacts():
print("you chose 4. display all contacts")
"""Displays all contacts."""
def main():
"""Main program loop."""
while True:
display_menu()
choice = input("Enter your choice: ").strip()
if choice == "1":
add_contact()
elif choice == "2":
search_contact()
elif choice == "3":
delete_contact()
elif choice == "4":
display_all_contacts()
else:
print("Invalid choice. Please try again.")
# Execute main
main()
```
%% Output
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
you chose 1. Add Contact
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
you chose 1. Add Contact
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
you chose 2. Search Contact
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
Invalid choice. Please try again.
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
you chose 1. Add Contact
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
Invalid choice. Please try again.
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
Invalid choice. Please try again.
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
Invalid choice. Please try again.
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
Invalid choice. Please try again.
Contact Manager
1. Add Contact
2. Search Contact
3. Update Contact
4. Delete Contact
5. Display All Contacts
6. Exit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment