美文网首页
day10 作业

day10 作业

作者: 木偶演员 | 来源:发表于2018-07-29 23:13 被阅读0次

    1.操作页面

    import register
    import landing
    import manage
    
    def page ():
        print(" $$欢迎来到大飞管理系统$$")
        print("$$$$$$$$$$$$$$$$$$$$$$$$$")
        print("$\t","\t\t\t\t","\t$")
        print("$\t","1.register","\t\t$")
        print("$\t", "2.landing", "\t\t\t$")
        print("$\t", "3.manage", "\t\t\t$")
        print("$\t", "4.quest", "\t\t\t$")
        print("$\t", "\t\t\t\t", "\t$")
        print("$$$$$$$$$$$$$$$$$$$$$$$$$")
    
    
    a = True
    while a:
        page()
        b = int(input("请输入与之对应的操作数字:"))
        if b ==1:
            register.user_register()
        if b ==2:
            landing.user_landing()
        if b == 3:
            landing.stu_manage()
        if  b ==4:
            a ==5
    

    2. 注册功能

    import json
    
    file2 = {}
    file1 = []
    key_name  = 'user_name'
    key_number = "user_key"
    key_number1 = "user_key1"
    user_student_key ="user_student"
    user_student = []
    
    
    def user_register():
        while True:
            try:
                with open("./user_file.json","r", encoding="utf-8") as f1:
                    file1 = json.load(f1)
            except:
                file1 = []
    
            while True:
                user_name = input("注册姓名:")
                for item in file1:
                    if user_name == item[key_name]:
                        print("用户名已存在,请登录")
                        return
                    else:
                        continue
                break
            user_key = input("输入密码:")
            user_key1 = input("确认密码:")
            if user_key == user_key1:
                user = {key_name: user_name,key_number:user_key,key_number1:user_key1,user_student_key:user_student}
                file1.append(user)
                with open("./user_file.json","w",encoding="utf-8") as f1:
                    json.dump(file1, f1)
                print("注册成功")
                return
            else:
                print("密码前后输入有误,请重新注册")
    

    3.登录功能

    
    import json
    
    file2 = {}
    file1 = []
    key_name  = 'user_name'
    key_number = "user_key"
    key_number1 = "user_key1"
    key_student = []
    user_student = []
    user_student_key ="user_student"
    user_input = ''
    stu_name_key = "stu_name"
    stu_age_key = "stu_age"
    stu_tel_key = "stu_tel"
    def user_landing():
        while True:
            global user_input
            user_input = input("输入用户名:")
            with open("./user_file.json","r",encoding="utf-8") as f1 :
                file1 = json.load(f1)
                for item in file1:
                    if user_input == item[key_name]:
                        break
            user_keying =input("请输入密码:")
            with open("./user_file.json", "r", encoding="utf-8") as f1:
                file1 = json.load(f1)
                for item in file1:
                    if user_keying == item[key_number]:
                        print("登陆成功")
                        return
                    else:
                        print("请重新登录")
    
    

    4.管理功能

    import  register
    import landing
    import json
    
    file2 = {}
    file1 = []
    key_name  = 'user_name'
    key_number = "user_key"
    key_number1 = "user_key1"
    key_student = []
    user_student = []
    user_student_key ="user_student"
    user_input = ''
    stu_name_key = "stu_name"
    stu_age_key = "stu_age"
    stu_tel_key = "stu_tel"
    def stu_manage():
    
        with open("./user_file.json", "r", encoding="utf-8") as f1:
            file1 = json.load(f1)
            print(file1)
            print(user_input,11111111)
            for index in range(len(file1)):
                if file1[index][key_name] == user_input:
                    user_student = file1[index]['user_student']
                    print(user_student)
    
            stu_name = input("请输入学生姓名:")
            stu_age = input("请输入学生年龄:")
            stu_tel = input("请输入学生电话:")
            student = {stu_name_key:stu_name,stu_age_key:stu_age,stu_tel_key:stu_tel}
            print(student)
            user_student.append(student)
            with open("./user_file.json", "w", encoding="utf-8") as f1:
                json.dump(file1, f1)
                print("添加成功")
                return
    

    相关文章

      网友评论

          本文标题:day10 作业

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