Getting Started with Python - User Login Program

_flag = False 
count = 0
users = [['ziv', '123'], ['alex', '12345']]
while count < 3:
username = input('Username:')
password = input('Password: ')
for user_item in users:
if username == user_item[0] and password == user_item[1]:
print('Login successful')
_flag = True # Change the login success flag to True
break # Used to jump out of the for loop
else:
print('Username or password error') # The for loop is executed normally (successful login will be broken, the else will not be executed, and vice versa), and then execute else
if _flag:
break # Used to jump out of the while loop
count += 1
else :
print('Username or password is wrong more than three times!') # Log in successfully while being broken, will not execute else, otherwise execute

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325690583&siteId=291194637