Mini List Project of Python(1)
Mini List Project of Python(1)
Objectives
- Practice basic list operations: add, remove, search, sort, and display.
Project Outline
Step-by-Step Implementation
Create a function to display a menu with options for the user to choose from.
def display_menu():
print("6. Exit")
def add_contact(contacts):
def remove_contact(contacts):
if contact["name"] == name:
contacts.remove(contact)
return
def search_contact(contacts):
name = input("Enter contact name to search: ")
if contact["name"] == name:
return
def display_contacts(contacts):
if not contacts:
else:
def sort_contacts(contacts):
contacts.sort(key=lambda x: x["name"])
def main():
contacts = []
while True:
display_menu()
if choice == "1":
add_contact(contacts)
remove_contact(contacts)
search_contact(contacts)
display_contacts(contacts)
sort_contacts(contacts)
print("Exiting program...")
break
else:
if __name__ == "__main__":
main()
To make the project more advanced, you can add the following features:
- Save contacts to a file and load them when the program starts.