HW8-06

初始
print('===========学==生==管==理==系==统==============')
def printinfo():
"打印任何传入的字符串"
print ("\t\t★1.学生注册: ")
print ("\t\t★2.学生登录: ")
print ("\t\t★3.修改学生信息:")
print ("\t\t★4.删除学生:")
print ("\t\t★5.退出:")

print('===========学==生==管==理==系==统==============')
answer = int(input('请选择(1-5):'))
return answer

ans = printinfo()

with open('files/text1.txt', 'r', encoding='utf-8') as j:

management_sys = j.read()

with open('files/text1.txt', 'w', encoding='utf-8') as j:

j.write('[{}]')

length = len(user_name)

def ger_all_user():
with open(r'D:\QF\语言基础\day12_文件操作和异常处理\files\text1.txt',encoding='utf-8') as f:
return json.loads(f.read())

def register():
"""注册"""

while True:
    count = 0
    user_name = input('添加学生(用户名不小于4-6位):')
    for i in user_name:
        count += 1
    if not (4 <= count <= 6):
        print('用户名输入有误,请重新输入!')
    else:
        print('添加成功!')


while True:
    password = input('请输入密码:')
    if 6 <= len(password) <= 12:
        break

拿到之前的注册的所有账号

all_user = ger_all_user()

if user_name in all_user:
    print('注册失败!账号已存在!')
    return

all_user[username] = password
with open(r'D:\QF\语言基础\day12_文件操作和异常处理\files\text1.txt',encoding='utf-8') as f:
    f.write(json.dumps(all_user))
print('注册成功')

def login():
username = input('请输入账号:')
password = input('请输入密码:')
all_user = ger_all_user()

判断注册

if username not in all_user:
    print('登录失败!该账号没有注册!')
    return
if all_user[username] != password:
    print('密码错误!请重新输入')
    return

ans = printinfo()
while True:
if ans == 1:
print('开始注册')
register()
elif ans == 2:
login()
elif ans == 3:
pass
elif ans == 4:
pass
else:
print('退出登录')
break

你可能感兴趣的:(HW8-06)