名片管理系统

card_lists = []
headline = ['name','tel','qq number','e-mail']
print('welcome to idcard management system')
# todo define 5 functions:
# 1.define menu imfomation:
def notice():
    print('*'*65)
    print("1.create a new idcard")
    print("2.show all ids")
    print("3.find idcard")
    print("0.exit"+'\n')
    print('*'*65)
# 2.define the function of creat new idcard
def create_new():
    global card_lists
    name = input('input your name:')
    tel = input("input your tel:")
    qq_num = input('input your qq number:')
    email = input('input your e-mail:')
    id_card ={'name':name,'tel':tel,"qq_num":qq_num,'email':email}
    card_lists.append(id_card)
# 3.define the function of revise idcard
def revise_id():
    global card_lists
    name = input('input your new name:')
    tel = input("input your new tel:")
    qq_num = input('input your new qq number:')
    email = input('input your new e-mail:')
    id_card ={'name':name,'tel':tel,"qq_num":qq_num,'email':email}
    return id_card
# 4.define the function of show all idcards
def show_all():
    global card_lists
    print('-'*65)
    for item in headline:
        print(item.center(12),end='\t')
    print('\n',end='')
    for id_card in card_lists:
        for key in id_card:
            print(id_card[key].center(12),end='\t')
        print('\n',end='')
    print('-'*65)
# 5.define the function of find idcard
def find_id():
    global card_lists
    name = input('input the name you wanna search:')
    for id_card in card_lists:
        if id_card['name'] == name:
            print('-'*65)
            for item in headline:
                print(item.center(12),end='\t')
            print('\n',end='')
            for key in id_card:
                print(id_card[key].center(12),end='\t')
            print('\n')
            print('0: delete a idcard,1: revise a idcard')
            print('-'*65)
            operation_choice = input()
            if operation_choice == '0':
                del_name = input('input name to delete:')
                for id_card1 in card_lists:
                    if del_name == id_card1['name']:
                        del card_lists[card_lists.index(id_card1)]
                break
            elif operation_choice == '1':
                revise_name = input('input name to revise:')
                new_idcard = revise_id()
                for id_card1 in card_lists:
                    if revise_name == id_card1['name']:
                        revise_idcard = id_card1
                card_lists[card_lists.index(revise_idcard)] = new_idcard
                break
            else:
                break
    else:
        print('not exist,please retry')
# main function
while True:
    notice()
    usr_input = eval(input("please select operate function:"))
    if usr_input != 0:
        print('Your selection is {}'.format(usr_input))
    if usr_input == 1:
        print('creat a new idcard')
        create_new()
    elif usr_input == 2:
        print('show all idcards')
        show_all()
    elif usr_input == 3:
        find_id()
    #if 0 then exit sys
    elif usr_input == 0:
        print('quit idcard management system')
        quit()
    else:
        print("no this selecton,please retry")
上一篇:代码回现 | 如何实现交易反欺诈?


下一篇:如何判断一个元素是否在可视区域内