while True:
name = input("请输入学生姓名:")
if name == 'q':
exit()
else:
f = open(r'E:\shujuchijiu\bb.txt', 'r', encoding='utf-8')
all_student = eval(f.read())
all_student.append(name)
print(all_student)
f = open(r'E:\shujuchijiu\bb.txt', 'w', encoding='utf-8')
f.write(str(all_student))
f.close()
作业
控制台登陆注册操作
def login_info():
print('='*50)
print(' '*2 ,'** ','欢迎来到X管理系统',' **')
print()
print()
print(" " * 10, '1.登陆')
print(" " * 10, '2.注册')
print(" " * 10, '3.退出')
print("=" * 50)
xuanze()
def xuanze():
global f1
global f2
a = int(input("请选择1-3:"))
if a == 1:
login1()
elif a == 2:
zhuce1()
elif a == 3:
f1.close()
f2.close()
print("结束退出")
exit()
else:
print("输入有误将返回")
login_info()
f1 = open(r'E:\shujuchijiu\zhanghao.txt', 'r', encoding='utf-8')
all_zhanghao = eval(f1.read())
f2 = open(r'E:\shujuchijiu\mima.txt', 'r', encoding='utf-8')
all_mima = eval(f2.read())
def zhuce1():
global all_zhanghao
global all_mima
zhanghao = input("请输入账号(3-6位):")
if not 3 <= len(zhanghao) <=6:
print("用户名格式错误")
zhuce1()
mima = input("请输入密码(6-12位)")
if not 6 <= len(mima) <=12:
print("密码格式错误")
zhuce1()
if zhanghao in all_zhanghao:
print("注册失败,该账号已经注册过!")
login_info()
else:
all_zhanghao.append(zhanghao)
all_mima.append(mima)
f1 = open(r'E:\shujuchijiu\zhanghao.txt', 'w', encoding='utf-8')
f1.write(str(all_zhanghao))
f2 = open(r'E:\shujuchijiu\mima.txt', 'w', encoding='utf-8')
f2.write(str(all_mima))
print("注册成功")
login_info()
def login1():
global all_zhanghao
global all_mima
zhanghao = input("请输入账号:")
mima = input("请输入密码:")
if zhanghao not in all_zhanghao:
print("该账号未注册")
login_info()
elif mima not in all_mima:
print("登陆失败,密码错误")
login_info()
else:
if mima != all_mima[all_zhanghao.index(zhanghao)]:
print("登陆失败,密码错误")
login_info()
else:
print("登陆成功")
login_info()
login_info()