day12-code

欢迎界面

def welcome(uid = ''):
    print("= " * 20)
    print("\t  欢迎%s进入系统" % uid)
    print("\t\t\t1.注册")
    print("\t\t\t2.登录")
    print("\t\t\t3.返回")
    print("\t\t\t4.退出")
    print("= " * 20)

注册系统

def logon():
    with open('files/注册表.txt', 'r',encoding='utf-8') as f:
        users = eval(f.read())
    uid = input("用户名:")
    key_word = input("密码:")
    users[uid] = key_word
    with open('files/注册表.txt', 'w', encoding='utf-8') as f:
        f.write(str(users))
    return users

# print(logon())

登录

def loading():
    with open('files/注册表.txt', 'r', encoding='utf-8') as f:
        users = eval(f.read())   # 得到文本中的数据

        if users == {}:
            print('无数据!请注册')
            welcome()
        else:
            while True:
                uid = input('请输入用户名:')
                if uid in users:
                    key_word = input('请输入密码:')
                    while True:
                        if key_word == users[uid]:
                            print('密码正确!登陆成功!')
                            # caozuojiemian()
                            break
                        else:
                            key_word = input('密码错误!请重新输入密码输入密码:')
                    break
                else:
                    print('用户名不存在!或用户名输入有误')
    return uid

操作学生信息界面

def caozuojiemian(uid = ''):
    print("= " * 20)
    print("\t  欢迎%s进入学生信息操作系统" % uid)
    print("\t\t\t1.添加")
    print("\t\t\t2.查看")
    print("\t\t\t3.查询")
    print("\t\t\t4.返回")
    print("\t\t\t5.退出")
    print("= " * 20)

1.添加

def add(uid = ''):
    print("=" * 40)
    print(">>>>名片新增:")
    name = input("请输入姓名:")
    qq = input("请输入qq:")
    email = input("请输入邮箱:")
    phone = input("请输入电话:")
    # 定义字典存数据
    dic = {"NAME": name, "QQ": qq, "EMAIL": email, "PHONE": phone}
    # 把字典老师姓名对应的值中
    with open('files/学生信息表.txt', 'r', encoding='utf-8') as f:
        users = eval(f.read())  # 得到总的字典
    list1 = eval(users[uid])
    list1.append(dic)

    users[uid] = str(list1)
    with open('files/学生信息表.txt', 'w', encoding='utf-8') as f:
        f.write(str(users))
    print("新增【%s】成功" % name)
    print(list)

查看所有名单

def check(uid):

    with open('files/学生信息表.txt', 'r', encoding='utf-8') as f:
        users = eval(f.read())  # 得到总的字典
    list = eval(users[uid])
    print("=" * 40)
    print(">>>>查看:")
    # 判断当list当中没有数据的时候无法显示
    if len(list) == 0:
        print("没有数据请先去添加")
        # 终止方法
        return
    print("姓名\t\t\t电话\t\t\t邮箱\t\t\tQQ")
    for item in list:
        print("%s\t\t\t%s\t\t\t%s\t\t\t%s" % (item["NAME"], item["PHONE"], item["EMAIL"], item["QQ"]))

3.查询

def query(uid):
    with open('files/学生信息表.txt', 'r', encoding='utf-8') as f:
        users = eval(f.read())  # 得到总的字典
    list = eval(users[uid])
    print("=" * 40)
    print(">>>>名片查询:")
    # 得到姓名
    name = input("请输入查询姓名:")
    # 在列表当中找
    # for else    当for循环当中提前终止跳出就不执行else如果顺序执行结束就执行else
    for item in list:
        if item["NAME"] == name:
            print("1,删除。\n2,修改。\n3,退出")
            key = input("请选择:")
            pass
            if key == "1":
                list.remove(item)

                users[uid] = str(list)
                with open('files/学生信息表.txt', 'w', encoding='utf-8') as f:
                    f.write(str(users))
                print("【%s删除成功】" % name)
                print(list)

            elif key == "2":
                print("请输入修改后的信息>>>>")
                item["NAME"] = input("姓名:")
                item["EMAIL"] = input("邮箱:")
                item["QQ"] = input("qq:")
                item["PHONE"] = input("电话:")
                users[uid] = str(list)
                with open('files/学生信息表.txt', 'w', encoding='utf-8') as f:
                    f.write(str(users))
                print("新增【%s】成功" % name)
                print(list)
                print("【%s修改成功】" % name)
            break
    else:
        print("抱歉!没有此人信息")

执行界面

if __name__ == '__main__':
    welcome()
    while True:
        key = input("请输入你要执行的操作:")

        print("你的选择是【%s】" % key)
        if key == "1":   # 注册
            logon()
            welcome()
        elif key == "2":  # 登录
            a = loading()

            caozuojiemian(uid=a)
            while True:
                key1 = input("请输入你要执行的学生操作:")

                if key1 == '1':   # 添加
                    add(uid=a)
                elif key1 == '2':  # 查看
                    check(a)
                elif key1 == '3':  # 查询
                    query(a)
                elif key1 == '4':   # 返回
                    caozuojiemian(uid=a)
                elif key1 == '5':  # 退出
                    print('退出学生信息操作系统!')
                    welcome(uid=a)
                    break
        elif key == "3":   # 返回
            welcome()
        elif key == "4": # 退出
            print('退出!')
            break

你可能感兴趣的:(day12-code)