2018-10-15day12-作业

print('欢迎来到学生管理系统')
print('===================')
print('1.登录 \n2.注册 \n3.退出 ')
print('====================')
num0=input('请输入选择项:1-3')
while True:
if num0=='1':
print('登录')
elif num0=='2':
print('注册')
else:
break
with open('./files/students.json') as f:
all_student = json.load(f)

def add_student():
"""
添加学生
"""
while True:
name = input('请输入学生的姓名:')
age = input('请输入学生的年龄:')
tel = input('请输入学生的电弧:')
# 创建学生对应的字典
student = {'name': name, 'age': age, 'tel': tel}
# 将学生添加到容器中
all_student.append(student)
# 将新的数据更新到本地文件中
with open('./files/students.json', 'w') as f:
json.dump(all_student, f)

    print('添加成功!')
    print('1.继续添加')
    print('2.返回上一层')
    input_value = input('请选择(1-2):')
    if input_value == '1':
        continue
    else:
        return

def show_student():
for student in all_student:
print(student)

while True:
print('======================')
print('1.添加学生')
print('2.显示学生信息')
print('3.退出')
print('======================')
input_value = input('请选择(1-3):')
if input_value == '1':
add_student()
elif input_value == '2':
show_student()
else:
print('退出成功!')
break
mport json

def register():

while True:
    with open('./files/student.json', 'r')as f:
        name = json.load(f)
    usr_name=input('请输入用户名:')
    if usr_name in name:
        print('此用户名已注册')
    else:
        mima=input('请输入密码:')
        name[usr_name]=mima
        with open('./files/student.json','w')as f1:
            json.dump(name,f1)
        print('注册成功!!!')
        break

def entry():
while True:
with open('./files/student.json', 'r')as f:
name = json.load(f)
usr_name=input('请输入账号')
if usr_name in name:
mima=input('请输入密码')
if name[usr_name]==mima:
print('登录成功')
break
else:
print('账号或密码错误')

print('欢迎来到学生管理系统')
print('===================')
print('1.登录 \n2.注册 \n3.退出 ')
print('====================')

while True:
num0 = input('请输入选择项:1-3')
if num0=='1':
entry()
elif num0=='2':
register()
else:
break

你可能感兴趣的:(2018-10-15day12-作业)