个人信息卡小程序(Python)

功能:增加个人信息,:查询个人信息,
主程序是product_main.py
调用模块product_info.py

#  以下是主程序product_main.py代码
#  Author:Bruce
#  Vesion:1.0
#  Discription: Business card management system
#  Last modified data: 2010.1.31

while True:
    # Display menu and option
    import product_info
    product_info.show_menu()
    action_str = input("please select the option:")
    print("your selection is [%s]" %action_str)
    # Call the specific function base on user's input
    if action_str in ["1","2","3"]:
        # Create new card
        if action_str == "1":
            product_info.create_card()
        # Display all card
        elif action_str == "2":
            product_info.show_allcards()
        # Search card
        else:
            product_info.search_card()

    # 0 (quit)
    elif action_str == "0":
        print("welcome to use the business card management system")
        break
    # Prompt message
    else:
        print("your input is wrong,please input the correct number")
# 以下是调用模块文件product_info代码
card_list = []


def show_menu():
    print("*" * 50)
    print("Welcome use business card management system V1.0")
    print("")
    print("1.Create new card")
    print("2.Display all card's information")
    print("3.Inquiry specific card")
    print("")
    print("0.Leave")
    print("*" * 50)


def create_card():
    # Define a empty list to record the input card information

    print("*" * 50)
    print("Create new card:")
    # Define 4 strings to store the input
    name_str = input("Please input your name:")
    phone_str = input("Please input your phone number:")
    wechat_str = input("Please input your Wechat number:")
    email_str = input("Please input your E-mail address:")
    card_dict = {"Name": name_str,
                 "Phone": phone_str,
                 "Wechat": wechat_str,
                 "E-mail": email_str}
    # Add the input dictionary to the list (it's empty at first time)
    card_list.append(card_dict)
    # Show cards info and prompt message
    print(card_list)
    print("added %s's card success" % name_str)


def show_allcards():
    print("*" * 50)
    print("All cards' information:")
    if len(card_list) == 0:
        print("There is no record,please create new record")
        return
    # Print key list
    for name in ["Name","Phone","Wechat","E-mail"]:
        print(name, end="\t\t")
    print("")
    # Print split line
    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["Wechat"],card_dict["E-mail"]))


def search_card():
    print("*" * 50)
    user_name = input("Please input user's name:")
    for card_dict in card_list:
        if card_dict["Name"] == user_name:
            for name in ["Name", "Phone", "Wechat", "E-mail"]:
                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["Wechat"], card_dict["E-mail"]))

            break
    else:
        print("The name you are searching does not exist")




你可能感兴趣的:(python)