This is based on a topic I found on the Internet, I copied it myself, and the following is my code
card_list = []def menu():print("*"*50)print("Welcome to [Business Card Management System] V1.0")print("1. Create a new business card (please add a space when entering the name with two characters!!)")print("2. Display all")print("3. Query business card")print("4. Delete business card")print("5. Modify business card")print()print("0. Exit the system")print("*"*50)def create_card():"""Create business card information:return: none"""print("-"*50)print("Function: Create a new business card, please fill in the content according to the following prompts: ")name = input("Enter name: ")sex = input("Enter gender:")tel = input("Enter phone: ")qq = input("Enter QQ:")email = input("Enter email: ")card_dict = {"name":name,"sex":sex,"qq":qq,"tel":tel,"email":email}card_list.append(card_dict)# print(card_list)print(f'Added successfully {card_dict["name"]} information...')def show_details():print("-" * 50)print("Function: Display existing business card information")if len(card_list) == 0:print("There is no business card record yet!")returnprint("name\t\tsex\t\ttel\t\t\t\tqq\t\t\t\temail")for card_dict in card_list:print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (card_dict["name"],card_dict["sex"],card_dict["qq"],card_dict["tel"],card_dict["email"]))def find_card():print("-" * 50)print("Function: Query information about existing business cards")find_name = input("Please enter the name you want to query: ")for card_dict in card_list:if card_dict["name"] == find_name:print("name\t\tsex\t\ttel\t\t\t\tqq\t\t\t\temail")print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (card_dict["name"],card_dict["sex"],card_dict["qq"],card_dict["tel"],card_dict["email"]))breakelse:print(f'No business card information found for {find_name}...')def delete_info():print("-" * 50)print("Function: delete information about existing business cards")del_name = input("Please enter the name of the card you want to delete: ")for card_dict in card_list:if card_dict["name"] == del_name:card_list.remove(card_dict)print("Deleted successfully...")def revise_card():print("-" * 50)print("Function: Modify the relevant information of the existing business card")find_name = input("Please enter the name of the business card you want to modify: ")for card_dict in card_list:if card_dict["name"] == find_name:card_dict["name"] = input("Please enter the modified name:")card_dict["sex"] = input("Please enter the modified gender:")card_dict["tel"] = input("Please enter the modified phone: ")card_dict["qq"] = input("Please enter the modified qq:")card_dict["email"] = input("Please enter the modified email: ")print(f'{find_name}'s business card modified successfully...')def main():while True:menu()num = input("Please enter the function to be operated: ")if num == "1":create_card()elif num == "2":show_details()elif num == "3":find_card()elif num == "4":delete_info()elif num == "5":revise_card()elif num == "0":print("Welcome next time")breakelse:print("Incorrect input, please try again!")main()
It's still a good check on your grasp of python's lists and dictionaries..
The title comes from: