使用名为'UserAccounts.txt'
的文件程序登录。def login():
print("logging in, ok")
counter = 0
while counter <= 5:
Username = input("Username:")
Password = input("Password:")
users = open("UserAccounts.txt","r")
entry = False
########### v checks file v #############
for record in users:
if record == Username:
Pass = record
if Pass == Password:
print("logged in")
entry = True
if entry == False:
print("Incorret, try again")
counter = counter + 1
print("LOCKED: Tried over 5 times")
无论输入什么,代码始终输出:
logging in, ok
Username:El
Password:Password
Incorret, try again
Username:
你知道为什么吗? (当用户名和密码在文件中时)
感谢您的帮助,祝您有美好的一天! (可能是简单的问题,但大脑无法正常工作)
答案 0 :(得分:0)
逐行读取时,该行用逗号分隔,因此在将它们声明为Pass
或def login():
print("logging in, ok")
counter = 0
while counter <= 5:
Username = input("Username:")
Password = input("Password:")
users = open("UserAccounts.txt","r")
entry = False
########### v checks file v #############
for record in users:
if record.split(',')[0] == Username:
Pass = record.split(',')[1] #assuming 34 is pwd. [2] if 'Secure' is the pwd
if Pass == Password:
print("logged in")
entry = True #maybe replace this line with "return" to stop while loop
if entry == False:
print("Incorret, try again")
counter = counter + 1
之前,需要用逗号分隔。
function promisify(callback) {
var promise1= new Promise(function(resolve,reject){
callback(resolve);
// resolve();
})
return promise1;
}
function myTimer(resolve) {
setTimeout(function(){
console.log('hello');
resolve();
},2000);
}
promisify(myTimer).then(function(){
alert("jello");
})