#! /usr/bin/python

def print_content():
    """
    Print the CONTENT of CardSystem
    """
    card_content = "1. New\n2. Show\n3. Search and Edit\n\n0. Exit"
    print("*" * 40)
    print("Welcome to Card System!\n%s" % card_content)
    print("*" * 40)

def modify_user_list(choice, user_list):
    while True:
        if choice == 1:
            card_name = input("Please Enter the Name of the Card: ")
            if len(card_name) == 0:
                print("The Name of the Card is Necessary!")
                continue
            card_phone = input("Please Enter the Phone of the Card: ")
            card_qq = input("Please Enter the QQ of the Card: ")
            card_email = input("Please Enter the Email of the Card: ")
            user_list.append({"name": card_name,
                              "phone": card_phone,
                              "qq": card_qq,
                              "email": card_email})
            break
        elif choice == 2:
            print("Name\tPhone\tQQ\tEmail")
            print("-" * 40)
            #print(user_list)
            for user in user_list:
                print("%s\t%s\t%s\t%s" % (str(user["name"]), str(user["phone"]), str(user["qq"]), str(user["email"])))
            break
        elif choice == 3:
            card_name = input("Please Enter the Name you want to search: ")
            if len(card_name) == 0:
                print("The Name of the Card is Necessary!")
                continue
            for user in user_list:
                if user["name"] == card_name:
                    print("Name\tPhone\tQQ\tEmail")
                    print("-" * 40)
                    print("%s\t%s\t%s\t%s" % (str(user["name"]), str(user["phone"]), str(user["qq"]), str(user["email"])))
                    break
            break
    return user_list

# Init the list of user.
user_list = []
# user_list = [{"name": "zhansan",
#               "phone": "111",
#               "qq": "222",
#               "email": "333"}]

while True:
    print_content()
    user_choice= input("Please Select (1/2/3/0): ")
    if user_choice.isdecimal and len(user_choice) == 1:
        user_choice = int(user_choice)
        if user_choice == 1 or user_choice == 2 or user_choice == 3:
            print("Your choice is: %d" % user_choice)
            user_list = modify_user_list(user_choice, user_list)
        elif user_choice == 0:
            print("Exited! See you next time.")
            break
        else:
            print("Cannot Find this choice: %s" % user_choice)
            continue
    else:
        print("Cannot Find this choice: %s" % user_choice)
        continue