Writing business card management system training based on python3 basic course is beneficial to familiarize with the use of basic python code.
cards_main.py
#! /usr/bin/python3 import cards_tools # Wireless looping, with the user deciding when to exit the system while True: # Display function menu cards_tools.show_menu() action_str = input("Please select the operation you wish to perform:") print("\n\n\n\n\n\n The operation you have selected is [%s] " % action_str) # 1,2,3 Operations for business cards if action_str in ["1", "2", "3"]: # 1. Handling of additional business cards if action_str == "1": cards_tools.new_card() # 2. Show all business cards elif action_str == "2": cards_tools.show_all() # 3. Search for business cards elif action_str == "3": cards_tools.search_card() # 0 Exit system elif action_str == "0": print("Welcome to using [Business Card Management System] again") break # If you don't want to write branching code immediately, a pass placeholder ensures that the program code is structured correctly. # pass # Other content entered incorrectly, need to prompt the user else: print("You have entered incorrectly, please make a new selection.")
cards_tools.py
# Record all business card dictionaries card_list = [] def show_menu(): """Show menu""" print("*" * 50) print("Welcome to Business Card Management System V 1.0") print("") print("1. Add a business card") print("2. Show all business cards") print("3. Querying/modifying/deleting business cards") print("") print("0. Exit the system.") print("*" * 50) def new_card(): """Add a business card""" print("-" * 50) print("Add a business card") # 1. prompts the user to enter business card details name_str = input("Please enter your name:") phone_str = input("Please enter the phone number:") qq_str = input("Please enter QQ:") email_str = input("Please enter mailbox:") # 2. Create a business card dictionary using user-entered information card_dict = {"name" : name_str, "phone" : phone_str, "qq" : qq_str, "email" : email_str} # 3. Add the business card dictionary to the list card_list.append(card_dict) print(card_dict) # 4. Prompting the user to add success print("\n\\n\n\n\n Add %s of business cards successfully." % name_str) def show_all(): """Show all business cards""" print("-" * 50) print("Show all business cards") # Determine if a business card record exists, if not, prompt the user and return to the if len(card_list) == 0: print("There are currently no business cards recorded, please add a business card") # return returns the result of the execution of a function # The code underneath will not be executed # If return is not followed by anything, it means it will return to the location where the function was called # And return no results return # Print form header for name in ["Name", "Telephone.", "QQ", "Mailbox."]: print(name, end="\t\t") print("") # Print the dividing line print("=" * 50) # Iterate through the list of business cards one at a time and output the dictionary information. for card_dict in card_list: print("%s\t\t%s\t\t%s\t\t%s" % (card_dict["name"], card_dict["phone"], card_dict["qq"], card_dict["email"])) def search_card(): """Search for business cards""" print("-" * 50) print("Search for business cards") # 1. prompts the user to enter the name to be searched for find_name = input("Please enter the name to be searched:") # 2. traverse the list of business cards, query the name to be searched, and prompt the user if it is not found for card_dict in card_list: if card_dict["name"] == find_name: print("name and surname\t\ttelephones\t\tQQ\t\tinbox") print("=" * 50) print("%s\t\t%s\t\t%s\t\t%s" % (card_dict["name"], card_dict["phone"], card_dict["qq"], card_dict["email"])) # Modify or delete a found business card. deel_card(card_dict) break else: print("Sorry, no %s found." % find_name) def deel_card(find_dict): """Handling found business cards :param find_dict: searched business card """ print(find_dict) action_str = input("Please select the action to be performed." "1 Modify 2 Delete 0 Return to previous level") if action_str == "1": find_dict["name"] = input_card_info(find_dict["name"], "name and surname(carriage return without modification (computing)):") find_dict["phone"] = input_card_info(find_dict["phone"], "telephones(carriage return without modification (computing)):") find_dict["qq"] = input_card_info(find_dict["qq"], "QQ(carriage return without modification (computing)):") find_dict["email"] = input_card_info(find_dict["email"], "mails(carriage return without modification (computing)):") print("Modification of business card successful!") elif action_str == "2": card_list.remove(find_dict) print("Business card deleted successfully!") elif action_str == "0": show_menu() def input_card_info(dict_value, tip_message): """Enter business card information :param dict_value:original value in dictionary :param tip_message:input tip text :return:Returns the content if the user has entered it, otherwise returns the original value. """ # 1. Prompt for modified information result_str = input(tip_message) # 2. return the input, if any if len(result_str) > 0: return result_str # 3. If there is no input, return the original value else: return dict_value
Source download:python3 implement business card management system
More study materials are available on the topic ofManagement system development》。
This is the whole content of this article.