python文件读取操作

时间:2024-01-04 17:31:50
 #IO操作
#模拟账号登录 data = [] #0=userName 1=password obj = open("login.txt","r")
for line in obj:
data.append(line.strip("\n"))
obj.close() while True:
print("---------")
print("| 登录 |")
print("---------")
userName = input("input your userName: ")
if(userName == data[0]):
password = input("input your password: ")
if(password == data[1]):
print("登录成功")
break
else:
print("密码错误")
else:
print("账号错误")