import json
class ReSystem:
def __init__(self):
with open('./id1.json', 'r', encoding='utf=8') as f:
list1 = f.read()
list1 = json.loads(list1)
self.all_id = list1
def register(self):
folat = True
while folat:
id1 = input('请输入要创建的账号:')
password1 = input('请输入要创建的密码:')
id1 = {'id': id1, 'password': password1}
if len(self.all_id) != 0:
for x in self.all_id:
if x['id'] != id1['id']:
continue
else:
print('账号已存在,创建失败!')
folat = False
break
else:
self.all_id.append(id1)
with open('./id1.json', 'w', encoding='utf=8') as f:
new_all = json.dumps(self.all_id)
f.write(new_all)
print('账号创建成功!')
print('账号创建成功!\n1.返回\n2.继续')
num = int(input('请选择1-2:'))
if num == 1:
break
else:
continue
else:
self.all_id.append(id1)
with open('./id1.json', 'w', encoding='utf=8') as f:
new_all = json.dumps(self.all_id)
f.write(new_all)
print('账号创建成功!\n1.返回\n2.继续')
num = int(input('请选择1-2:'))
if num == 1:
break
else:
continue
def enter1(self):
en_id = input('请输入账号:')
en_password = input('请输入密码:')
for x in self.all_id:
if x['id'] == en_id:
if x['password'] == en_password:
print('登录成功!')
break
else:
print('密码错误!')
break
else:
print('用户名不存在!')
def enter(self):
while True:
str1 = """===========================================
欢迎来到XX学生管理系统:
1.登 录
2.注 册
3.退 出"""
print(str1)
num = input('请选择(1-3):')
if num == '1':
self.enter1()
elif num == '2':
self.register()
else:
exit()
s1 = ReSystem()
s1.enter()
day17作业
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。