函数
"""__author__ = 何志成"""
import json
def homepage1():
"""登录注册页面"""
print('''
====================================================
❀欢迎来到王者学生管理系统❀
♦1. 登 录
♦2. 注 册
♦3. 退 出
====================================================
''')
def register(list1: list):
"""注册添加用户"""
while True:
name = input('请输入用户名(3-6位):')
if 3 <= len(name) <= 6:
break
else:
print('账号输入错误,请重新输入')
while True:
password = input('请输入密码(11-16位):')
if 11 <= len(password) <= 16:
break
else:
print('密码输入错误,请重新输入')
list1.append({'name': name, 'password': password})
def name1():
"""登录输入"""
while True:
name = input('请输入用户名(3-6位):')
if 3 <= len(name) <= 6:
break
else:
print('账号输入错误,请重新输入')
return name
def password():
while True:
password = input('请输入密码(11-16位):')
if 11 <= len(password) <= 16:
break
else:
print('密码输入错误,请重新输入')
return password
def look_load():
"""获取json里面的数据"""
while True:
try:
with open('teacher.json', encoding='utf-8')as f:
json.load(f)
break
except TypeError:
print('类型错误')
def new_dump(all_student):
"""更新json数据"""
with open('teacher.json', 'w', encoding='utf-8')as f:
json.dump(all_student, f)
def registration_page():
# 获取数据
with open('teacher.json', encoding='utf-8')as f:
all_student = json.load(f)
register(all_student)
# 更新数据
with open('teacher.json', 'w', encoding='utf-8')as f:
json.dump(all_student, f)
# print(all_student, end=' ')
def main():
pass
if __name__ == '__main__':
main()
# homepage1()
# register([])
# registration_page()
look_load()
调用
"""__author__ = 何志成"""
import homepage
import json
def main():
while True:
homepage.homepage1()
import1 = input('请选择(1-3):')
while True:
if import1 == '1':
name = homepage.name1()
password = homepage.password()
new_load = homepage.look_load()
print(type(new_load),new_load)
# for item in new_load:
# print(type(item))
# if item['name'] == name:
# print('账号正确')
# if item['password'] == password:
# print('登录成功!')
# print('登录成功')
elif import1 == '2':
# homepage.look_load()
homepage.registration_page()
print('注册成功')
break
else:
break
if __name__ == '__main__':
main()
网友评论