-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6601 from MazeJack/Adding/Python_contact_manageme…
…nt_application Adding/python contact management application
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
contacts = [] | ||
|
||
def add_contact(): | ||
name = input("Enter the contact's name: ") | ||
number = input("Enter the contact's phone number: ") | ||
contact = (name, number) | ||
contacts.append(contact) | ||
print("Contact added successfully.") | ||
|
||
def list_contacts(): | ||
if not contacts: | ||
print("No contacts found.") | ||
else: | ||
print("Your contacts:") | ||
for i, (name, number) in enumerate(contacts, start=1): | ||
print(f"{i}. {name}: {number}") | ||
|
||
while True: | ||
print("\nOptions:") | ||
print("1. Add a contact") | ||
print("2. List contacts") | ||
print("3. Quit") | ||
|
||
choice = input("Enter your choice: ") | ||
|
||
if choice == "1": | ||
add_contact() | ||
elif choice == "2": | ||
list_contacts() | ||
elif choice == "3": | ||
print("Exiting the Contact Management App.") | ||
break | ||
else: | ||
print("Invalid choice. Please try again.") |
34 changes: 34 additions & 0 deletions
34
Add Code Here/PYTHON/Python_contact_management_application.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
contacts = [] | ||
|
||
def add_contact(): | ||
name = input("Enter the contact's name: ") | ||
number = input("Enter the contact's phone number: ") | ||
contact = (name, number) | ||
contacts.append(contact) | ||
print("Contact added successfully.") | ||
|
||
def list_contacts(): | ||
if not contacts: | ||
print("No contacts found.") | ||
else: | ||
print("Your contacts:") | ||
for i, (name, number) in enumerate(contacts, start=1): | ||
print(f"{i}. {name}: {number}") | ||
|
||
while True: | ||
print("\nOptions:") | ||
print("1. Add a contact") | ||
print("2. List contacts") | ||
print("3. Quit") | ||
|
||
choice = input("Enter your choice: ") | ||
|
||
if choice == "1": | ||
add_contact() | ||
elif choice == "2": | ||
list_contacts() | ||
elif choice == "3": | ||
print("Exiting the Contact Management App.") | ||
break | ||
else: | ||
print("Invalid choice. Please try again.") |