def welcome():
print('欢迎进入系统!')
print('**************************')
print('** 请选择对应功能: **')
print('** 1. 登录 **')
print('** 2. 注册 **')
print('** 3. 退出系统 **')
print('**************************')
choice = input('请输入你的选择: ')
if choice == '1':
return '1'
elif choice == '2':
return '2'
else:
return '3'
def loadUserInfo():
with open('../file/user_info.txt', 'r', encoding='utf-8') as f1:
result = f1.readlines()
# 处理信息
userInfo = {i.replace(';\n', '').split(':')[0]:i.replace(';\n', '').split(':')[1] for i in result[1:]}
return userInfo
def register():
with open('../file/user_info.txt', 'a', encoding='utf-8') as f2:
username = input('请输入用户名: ')
if username in userInfo.values():
print('用户名已存在')
else:
password = input('输入密码:')
f2.write(f'{username}:{password};\n')
print('注册成功')
def login():
# 1. 输入账号和密码
username = input('请输入账号:')
password = input('请输入密码:')
# 2. 判断登录是否成功
# 1)账号是否已经注册
if username in userInfo.keys():
if password == userInfo[username]:
print('登录成功')
else:
print('用户名或密码错误')
else:
print('用户名或密码错误')
if __name__ == '__main__':
choice = welcome()
userInfo = loadUserInfo()
while True:
if choice == '1':
login()
break
elif choice == '2':
register()
break
else:
break
01-07
3059
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-08
498
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-01
408
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-18