美文网首页
名片管理系统

名片管理系统

作者: 愿你有闯荡风雪的骁勇 | 来源:发表于2018-11-02 20:57 被阅读0次

List=[]

def print_menu():

    print('1.新建名片')

    print('2.删除名片')

    print('3.修改名片')

    print('4.查询名片')

    print('5.显示所有名片')

    print('6.退出管理系统')

def m_add():

    new_name=input('输入姓名:')

    new_sex=input('输入性别:')

    new_age=input('输入年龄:')

    new_QQ=input('输入QQ:')

    card={}#因为是多条记录,每一条记录都是name:姓名,sex:性别,age:年龄,QQ:QQ.这个就是必须放在字典这种类型里才合适啊,然后是多条,就放到一个列表里。

    card['name']=new_name

    card['sex'] = new_sex

    card['age'] = new_age

    card['QQ'] = new_QQ

    global List

    List.append(card)#空列表加字典,呵呵,头一次见。

    print(List)

def m_del():

    global List

    fname=input('输入你要删除名片的姓名:')

    fflag=0

    for temp in List:

        if temp['name']==fname:

            List.remove(temp)

            print(List)

            fflag=1

            break

    if fflag==0:

        print('没有这张名片!')

def m_mofify():

    global List

    mname=input('输入你要修改信息名片的姓名:')

    flag=0

    for temp in List:

        if mname==temp['name']:

            flag=1

            #print('%s\t%s\t%s\t%s' % (temp['name'], temp['sex'], temp['age'], temp['QQ']))

            print('%s\t%s\t%s\t%s'%(temp['name'], temp['sex'],temp['age'],temp['QQ']))

            print('1.姓名 2.性别  3.年龄 4.QQ 5.退出')

            mchoice=int(input( '选择要修改的信息:'))

            #while True:

            if mchoice == 1:

                temp['name'] = input('输入修改后的姓名:')

            elif mchoice == 2:

                temp['sex'] = input('输入修改后的性别:')

            elif mchoice == 3:

                temp['age'] = input('输入修改后的年龄:')

            elif mchoice == 4:

                temp['QQ'] = input('输入修改后的QQ:')

            elif mchoice == 5:

                break

            else:

                print('输入错误')

            print('姓名\t性别\t年龄\tQQ')

            print('%s\t%s\t%s\t%s' % (temp['name'], temp['sex'], temp['age'], temp['QQ']))

            break

    if flag==0:

        print('没有这张名片!')

def m_find():

    fname=input('输入你要查询的名片的姓名:')

    fflag=0

    for temp in List:

        if temp['name']==fname:

            fflag = 1

            print('姓名\t性别\t年龄\QQ')

            print('%s\t%s\t%s\t%s' % (temp['name'], temp['sex'], temp['age'], temp['QQ']))

            break

        if fflag==0:

            print('no card')

def m_showall():

    global List

    print('姓名\t性别\t年龄\tQQ')

    for temp in List:

        print('%s\t%s\t%s\t%s' % (temp['name'], temp['sex'], temp['age'], temp['QQ']))

def main():

    print_menu()

    while True:

        choice=int(input('请输入你的选择:'))

        if choice==1:

            m_add()

        elif choice==2:

            m_del()

        elif choice==3:

            m_mofify()

        elif choice==4:

            m_find()

        elif choice==5:

            m_showall()

        elif choice==6:

            break

        else:

            print('操作错误,输入有误!')

main()

相关文章

网友评论

      本文标题:名片管理系统

      本文链接:https://www.haomeiwen.com/subject/dqdfxqtx.html