Based on python3 basic courses, writing business card management system training is conducive to familiarizing with the use of python basic code.
cards_main.py
#! /usr/bin/python3
import cards_tools
# Wireless loop, the user decides when to exit the system
while True:
# Show function menu
cards_tools.show_menu()
action_str =input("Please select the operation you want to perform:")print("nnnnnThe operation you choose is [%s】 "% action_str)
# 1,2,3 Operations for business cards
if action_str in["1","2","3"]:
# 1. Processing of new business cards
if action_str =="1":
cards_tools.new_card()
# 2. Show all business cards
elif action_str =="2":
cards_tools.show_all()
# 3. 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 branch code immediately, use pass to ensure the correct structure of the program code
# pass
# Other input errors, need to prompt the user
else:print("Your input is incorrect, please select again")
cards_tools.py
# Record all business card dictionaries
card_list =[]
def show_menu():"""Show menu"""print("*"*50)print("Welcome to use [Business Card Management System] V 1.0")print("")print("1.Add business card")print("2.Show all business cards")print("3.Inquire/modify/Delete business card")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 the information entered by the user to build 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_dict)
# 4. Prompt the user to add successfully
print("nnnnn add%s business card success"% 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 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="tt")print("")
# Print dividing line
print("="*50)
# Traverse the list of business cards and output dictionary information once
for card_dict in card_list:print("%stt%stt%stt%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. 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 not found
for card_dict in card_list:if card_dict["name"]== find_name:print("Name tt Phone ttQQtt Email")print("="*50)print("%stt%stt%stt%s"%(card_dict["name"],
card_dict["phone"],
card_dict["qq"],
card_dict["email"]))
# Modify or delete the found business card
deel_card(card_dict)breakelse:print("Sorry, not found%s"% find_name)
def deel_card(find_dict):"""Process found business cards
: param find_dict:Searched business cards
"""
print(find_dict)
action_str =input("Please select the action to be performed""1 modify 2 delete 0 return to the previous level")if action_str =="1":
find_dict["name"]=input_card_info(find_dict["name"],"Name(Enter without modification):")
find_dict["phone"]=input_card_info(find_dict["phone"],"phone(Enter without modification):")
find_dict["qq"]=input_card_info(find_dict["qq"],"QQ(Enter without modification):")
find_dict["email"]=input_card_info(find_dict["email"],"mail(Enter without modification):")print("Successfully modified the business card!")
elif action_str =="2":
card_list.remove(find_dict)print("Successfully deleted the business card!")
elif action_str =="0":show_menu()
def input_card_info(dict_value, tip_message):"""Enter business card information
: param dict_value:The original value in the dictionary
: param tip_message:Enter prompt text
: return:If the user enters the content, return the content, otherwise return the original value
"""
# 1. Prompt for modified information
result_str =input(tip_message)
# 2. If there is input, return the input information
iflen(result_str)0:return result_str
# 3. If there is no input, return the original value
else:return dict_value
Source code download: python3 realizes business card management system
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 your study, and I hope you can support website (zalou.cn).
Recommended Posts