card_main.py
import card_tool
# welcome UI
while True:
card_tool.show_menu()
action_str = input("Please select the action you want to perform")
print("your action is [%s]" % action_str)
if action_str in ["1", "2", "3"]:
if action_str == "1":
card_tool.new_card()
elif action_str == "2":
card_tool.show_all()
elif action_str == "3":
card_tool.search_card()
else:
print("error 1")
elif action_str == "0":
print("welcome to use this system again")
break
else:
print("your action is incorrect,please select again")
card_tool.py
card_list = []
def show_menu():
print("*" * 50)
print("Welcome to use business card management system")
print("")
print("1.Add new business cards")
print("2.Show all business cards")
print("3.Search business cards")
print("")
print("0.Exit system")
print("*" * 50)
def new_card():
print("-" * 50)
print("Add new business cards:")
name_str = input("please input name:")
phone_str = input("please input phone number:")
qq_str = input("please input QQ number:")
email_str = input("please input Email:")
card_dict = {"name": name_str,
"phone": phone_str,
"QQ": qq_str,
"Email": email_str
}
card_list.append(card_dict)
print(card_list)
print("Add business card of %s successfully!" % name_str)
def show_all():
print("-" * 50)
print("Show all business cards")
if len(card_list) == 0:
print("There are no cards,please use function 1 to add cards")
else:
for name in ["name", "phone", "QQ", "Email"]:
print(name, end="\t\t")
print("")
print("=" * 50)
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():
print("-" * 50)
print("search business cards")
find_name = input("Please input the name you want to search:")
for card_dict in card_list:
if card_dict["name"] == find_name:
print("Get it!")
for name in ["name", "phone", "QQ", "Email"]:
print(name, end="\t\t")
print("")
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"]))
deal_card(card_dict)
break
else:
print("Sorry,can not find %s" % find_name)
def deal_card(find_dict):
print(find_dict)
action_str = input("Please choose action 1 modify 2 delete 3 return")
if action_str == "1":
find_dict["name"] = input_card_info(find_dict["name"], input("name: "))
find_dict["phone"] = input_card_info(find_dict["phone"], input("phone: "))
find_dict["qq"] = input_card_info(find_dict["name"], input("QQ: "))
find_dict["email"] = input_card_info(find_dict["name"], input("Email: "))
print("Modify the business card")
elif action_str == "2":
card_list.remove(find_dict)
print("Delete the business card successfully!")
elif action_str == "3":
pass
else:
pass
def input_card_info(dict_value, tip_message):
if len(tip_message) > 0:
return tip_message
else:
return dict_value