"""__author__=Hanlin"""
import json
def p1():
print('====================================\n')
print('欢迎来到学生管理系统\n')
print('====================================\n')
print('1.登录学生管理系统\n')
print('2.注册账号密码\n')
print('3.退出学生管理系统\n')
print('====================================\n')
action = input('>>')
if action == '1':
return 1
elif action == '2':
return 2
elif action == '3':
return 3
# =================登录==========================
def login():
with open('../idPs.json', 'r', encoding='utf-8') as f:
id = input('请输入你的账号:')
ps = input('请输入你的密码:')
content = f.read()
n_content = json.loads(content)
for n in n_content:
if id == n['id']:
if ps == n['ps']:
print('登录成功')
break
else:
print('密码错误')
break
else:
print('请注册账号')
# =============================signup===========================
def signup():
with open('../idPs.json', 'r', encoding='utf-8') as f:
content = f.read()
n_content = json.loads(content)
new_id = input('请输入你要注册的账号:')
new_ps = input('请输入你要注册的密码:')
for n in n_content:
if n['id'] == new_id:
print('你输入的账号已被注册')
break
else:
n_content.append({'id': new_id, 'ps': new_ps})
print('恭喜你,注册成功啦!!!')
with open('../idPs.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(n_content))
# =============================main=============================
while True:
value_1 = p1()
if value_1 == 3:
exit()
elif value_1 == 2:
value_1_2 = signup()
elif value_1 == 1:
value_1_1 = login()
else:
print('指令错误')
continue
json文件
[]