Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pyeng Lectures
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Riccardo Caracciolo
Pyeng Lectures
Commits
21979e02
Commit
21979e02
authored
3 months ago
by
Jöran Frey
Browse files
Options
Downloads
Patches
Plain Diff
added exercise
parent
1f888602
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unit-5/Lifecoding Session/Extra Exercise/Contact Manager.ipynb
+212
-0
212 additions, 0 deletions
...5/Lifecoding Session/Extra Exercise/Contact Manager.ipynb
with
212 additions
and
0 deletions
unit-5/Lifecoding Session/Extra Exercise/Contact Manager.ipynb
0 → 100644
+
212
−
0
View file @
21979e02
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extra Exercises"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build a Contact Manager\n",
"\n",
"Write a Python program that manages a list of contacts. Programm functions that allow a User to add, search, delete, and display contacts.\n",
"\n",
"```Hint```: the basic framework is already there, you just have to programme the functions"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"you chose 1. Add Contact\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"you chose 1. Add Contact\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"you chose 2. Search Contact\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"Invalid choice. Please try again.\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"you chose 1. Add Contact\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"Invalid choice. Please try again.\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"Invalid choice. Please try again.\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"Invalid choice. Please try again.\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n",
"Invalid choice. Please try again.\n",
"\n",
"Contact Manager\n",
"1. Add Contact\n",
"2. Search Contact\n",
"3. Update Contact\n",
"4. Delete Contact\n",
"5. Display All Contacts\n",
"6. Exit\n"
]
}
],
"source": [
"# Contact Manager Program\n",
"\n",
"# List to store contacts with some examples\n",
"contacts = [ {\"name\": \"Alice Johnson\", \"phone\": \"1234567890\", \"email\": \"alice@example.com\"},\n",
" {\"name\": \"Bob Smith\", \"phone\": \"9876543210\", \"email\": \"bob.smith@example.com\"},\n",
" {\"name\": \"Charlie Brown\", \"phone\": \"5556667777\", \"email\": \"charlie.brown@example.com\"},\n",
" {\"name\": \"John Do\", \"phone\": \"1112223333\", \"email\": \"diana.prince@example.com\"}]\n",
"\n",
"def display_menu():\n",
" \"\"\"Displays the menu.\"\"\"\n",
" print(\"\\nContact Manager\")\n",
" print(\"1. Add Contact\")\n",
" print(\"2. Search Contact\")\n",
" print(\"3. Update Contact\")\n",
" print(\"4. Delete Contact\")\n",
" print(\"5. Display All Contacts\")\n",
" print(\"6. Exit\")\n",
"\n",
"def add_contact():\n",
" print(\"you chose 1. Add Contact\")\n",
" \n",
"\n",
"\n",
"\n",
"def search_contact():\n",
" print(\"you chose 2. Search Contact\")\n",
" \"\"\"Searches for a contact by name.\"\"\"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"def delete_contact():\n",
" print(\"you chose 3. delete a contact\")\n",
" \"\"\"Deletes a contact.\"\"\"\n",
"\n",
"\n",
"\n",
"\n",
"def display_all_contacts():\n",
" print(\"you chose 4. display all contacts\")\n",
" \"\"\"Displays all contacts.\"\"\"\n",
"\n",
"\n",
"\n",
"\n",
"def main():\n",
" \"\"\"Main program loop.\"\"\"\n",
" while True:\n",
" display_menu()\n",
" choice = input(\"Enter your choice: \").strip()\n",
" if choice == \"1\":\n",
" add_contact()\n",
" elif choice == \"2\":\n",
" search_contact()\n",
" elif choice == \"3\":\n",
" delete_contact()\n",
" elif choice == \"4\":\n",
" display_all_contacts()\n",
" else:\n",
" print(\"Invalid choice. Please try again.\")\n",
"\n",
"# Execute main\n",
"main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% 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("
\n
Contact 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment