The basic exercise case of python-business card management system, a case exercise of a console program, the platform is pycharm2017. The code was written while watching the python video study, pycharm runs without problems.
system requirement
1、 The program starts, the welcome interface of the business card management system is displayed, and the function menu is displayed
Welcome to use [Business Card Management System] V1.0
1 New business card
2 display all
3 Query business cards
0 Exit system
2、 Users select different functions with numbers
3、 Perform different functions according to function selection
4、 The user's business card needs to record the user's name, phone number, QQ, email
5、 If the designated business card is found, the user can choose modify or delete business card
step
Frame construction
Add business card
Show all business cards
Query business cards
Modify and delete the business card after the query is successful
Let Python programs run directly
**Code: **
For the convenience of operation, the main function and the custom function are divided into two files for the convenience of readers.
code show as below:
mian:
import cards_tools
# Wireless loop, the user decides when to exit the loop
while True:
# Show function menu
cards_tools.show_menu()
action_str =input("Please select the operation you want to perform:")print("The operation you choose is [%s】"% action_str)
# 1,2,3 Operations for business cards
if action_str in["1","2","3"]:
# Add business card
if action_str =="1":
cards_tools.new_card()
# display all
elif action_str =="2":
cards_tools.show_all()
# Query business cards
elif action_str =="3":
cards_tools.search_card()
# 0 Exit system
elif action_str =="0":print("Welcome to use [Business Card Management System] again")break
# If you don’t want to write the code inside the branch immediately when you open the program
# You can use the pass keyword to represent a placeholder to ensure that the code structure of the program is correct
# When the program is running, the pass keyword will not perform any operation!
# pass
# Other input errors, need to prompt the user
else:print("Your input is incorrect, please select again!")
tools:
# Record all business card dictionaries
card_list =[]
def show_menu():"""Show menu"""print("*"*50)print("Welcome to use [Business Card Management System] V1.0")
# print("")print("1.Add business card")print("2.display all")print("3.Search for business cards")
# print("")print("0.Exit system")print("*"*50)
def new_card():"""Add business card"""print("-"*50)print("Add business card")
# 1. Prompt the user to enter the details of the business card
name_str =input("Please type in your name:")
phone_str =input("Please enter the phone:")
qq_str =input("Please enter QQ:")
email_str =input("please input your email:")
# 2. Use user input information to create a business card dictionary
card_dict ={"name": name_str,"phone": phone_str,"QQ": qq_str,"email": email_str}
# 3. Add business card dictionary to the list
card_list.append(card_dict)print(card_list)
# 4. Prompt the user to add successfully
print("Add to%s'business card is successful!"% name_str)
def show_all():"""Show all business cards"""print("-"*50)print("Show all business cards")
# Determine whether there is a business card record, if not, prompt the user and return
iflen(card_list)==0:print("There is currently no business card record, please use the new function to add a business card!")
# return can return the execution result of a function
# The code below will not be executed
# If there is nothing after return, it means that it will return to the place where the function was called
# And returns no results
return
# Print head
for name in["Name","phone","QQ","mailbox"]:print(name, end="\t\t")print("")
# Print divider
print("="*50)
# Traverse the list of business cards and output dictionary information in turn
for card_dict in card_list:print("%s\t\t%s\t\t%s\t\t%s\t\t"%(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. Prompt the user to enter the name to search
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\t\t phone\t\tQQ\t\t mailbox")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 and delete the business card records found
deal_card(card_dict)breakelse:print("Sorry, not found%s!"% find_name)
def deal_card(find_dict):"""Process the found business cards
: param find_dict:Business card found
"""
print(find_dict)
action_str =input("Please select the action to be performed""[1]modify[2]delete[0]Return to the previous menu")if action_str =="1":
find_dict["name"]=input_card_info(find_dict["name"],"Name:")
find_dict["phone"]=input_card_info(find_dict["phone"],"phone:")
find_dict["QQ"]=input_card_info(find_dict["QQ"],"qq:")
find_dict["email"]=input_card_info(find_dict["email"],"email: ")print("Successfully modified business card")if action_str =="2":
card_list.remove(find_dict)print("Successfully deleted business card")
def input_card_info(dict_value, tip_message):"""Enter business card information
: param dict_value:The original value in the dictionary
: param tip_message:Prompt text
: return:If the user enters content, return the content, otherwise return the original value in the dictionary
"""
# 1. Prompt the user for input
result_str =input(tip_message)
# 2. Judge the user's input, if the user enters the content, return the result directly
iflen(result_str)0:return result_str
# If the user does not input content, return the original value in the dictionary
else:return dict_value
For more learning materials, please pay attention to the topic "Management System Development".
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts