day10作业

2018-09-03  本文已影响0人  上邪5415

编写千峰学生管理系统。

logon_student_account = {}
student_info_dict={}
login_count_student_info_dict={}
while True:
    str1 = 'welcome QianFeng student manager system'
    print(str1)
    print('          1.Login登录')
    print('          2.logon注册')
    print('          3.Quit')
    num1 =int(input('请选择:'))
    if num1 == 2:
        while True:
            a =0  #借助a的值来执行最后的break,跳出外面的while循环。
            logon_student_account_name =input('请输入用户名(3-10位):')
            if len(logon_student_account_name) >=3 and len(logon_student_account_name)<=10 and not logon_student_account_name in logon_student_account:
                print('用户名可用!')
                while True:
                    logon_student_account_password = input('请输入密码(6-16位):')
                    if 6<=len(logon_student_account_password)<=16:
                        logon_student_account_password1=input('请再次输入密码):')
                        if logon_student_account_password == logon_student_account_password1:
                            print('注册成功')
                            logon_student_account.setdefault(logon_student_account_name,logon_student_account_password)
                            a= 1
                            break
                        else:
                            print('密码不对,请重新输入')
                    else:
                        print('密码不符合要求')
            else:
                print('用户名不可用,请重新输入')
            if a == 1:
                break

    if num1 ==1:
        while True:
            login_student_account_name = input('请输入用户名:')
            if login_student_account_name in logon_student_account:
                login_student_account_password = input('请输入密码:')
                if login_student_account_password==logon_student_account[login_student_account_name]:
                    print('登陆成功!!!')
                    break
            else:
                print('用户名不正确!!!')
        while True:
            print('1.Add Student')
            print('2.Find Student')
            print('3.Delete Student')
            print('4.Revise StudentInfo')
            print('5.Back')
            number=input('请选择:')
            if number in '1,2,3,4,5':
                num2 =int(number)
            else:
                print('请填写正确选项!!!')
                continue
            if num2 == 1:
                while True:
                    add_student_name = input('请输入学生的姓名:')
                    add_student_age = input('请输入学生的年龄:')
                    add_student_tel = input('请输入学生的电话:')
                    student_info_dict.setdefault(add_student_name,[add_student_age,add_student_tel]) #将学生信息作为一个键值对放在字典中
                    login_count_student_info_dict.setdefault(login_student_account_name,student_info_dict)  #将登录的账户名与所有学生的信息字典关联起来
                    print('添加成功!')
                    print('1.继续添加')
                    print('2.返回')
                    num = int(input('请选择:'))
                    if num == 2:
                        break
            if num2 ==2:
                find_student_name = input('请输入查找学生姓名:')
                if login_count_student_info_dict.get(login_student_account_name) == None:
                    print('没有添加学生信息')
                elif find_student_name in login_count_student_info_dict[login_student_account_name]:
                    print('姓名:%s,年龄:%s,电话:%s'%(find_student_name,login_count_student_info_dict[login_student_account_name][find_student_name][0],login_count_student_info_dict[login_student_account_name][find_student_name][1]))
                else:
                    print('查无此人!!!')
            if num2 ==3:
                delete_student_name=input('请输入删除学生姓名:')
                if login_count_student_info_dict.get(login_student_account_name) == None:
                    print('没有添加学生信息')
                elif delete_student_name in login_count_student_info_dict[login_student_account_name]:
                    del login_count_student_info_dict[login_student_account_name][delete_student_name]
                    print('删除成功!!!')
                else:
                    print('无此学生,无法删除!!!')
                if login_count_student_info_dict.get(login_student_account_name) == None:
                    continue
                if login_count_student_info_dict[login_student_account_name] != {}:
                    print('剩余学生信息:')
                    for item in login_count_student_info_dict[login_student_account_name]:
                        print('姓名:%s,年龄:%s,电话:%s' % (
                        item, login_count_student_info_dict[login_student_account_name][item][0],
                        login_count_student_info_dict[login_student_account_name][item][1]))
            if num2 == 4:
                revise_student_name = input('请输入要修改学生姓名:')
                if login_count_student_info_dict.get(login_student_account_name) == None:
                    print('没有添加学生信息')
                elif revise_student_name in login_count_student_info_dict[login_student_account_name]:
                    print('1.修改年龄')
                    print('2.修改电话')
                    num = int(input('请选择:'))
                    if num ==1:
                        new_age = input('请输入新的年龄:')
                        login_count_student_info_dict[login_student_account_name][revise_student_name][0]=new_age
                    if num ==2:
                        new_tel = input('请输入新的的电话:')
                        login_count_student_info_dict[login_student_account_name][revise_student_name][0] = new_tel
                if login_count_student_info_dict.get(login_student_account_name) == None:
                    continue
                if login_count_student_info_dict[login_student_account_name] != {}:
                        print('修改后学生信息:')
                        for item in login_count_student_info_dict[login_student_account_name]:
                            print('姓名:%s,年龄:%s,电话:%s' % (
                                item, login_count_student_info_dict[login_student_account_name][item][0],
                                login_count_student_info_dict[login_student_account_name][item][1]))
            if num2 ==5:
                break
    if num1 ==3:
        break
上一篇下一篇

猜你喜欢

热点阅读