DAY1 practice

Requirements: The user is logged in (three chances to make mistakes) and each time the user makes a mistake, the remaining number of mistakes is displayed (hint: use string formatting),
If you use it three times, ask if you want to try again and give it three more chances. If you don't want to try it, say there is no chance.


list = [{'username':'xyn','password':'789'},
{'username': 'xxx', 'password': '123'},
{'username': 'yyy', 'password ': '456'},]
count=0 #Have been entered several times
b=6 #Total input times
a=3 #Reminder the remaining times
while count<3:
username = input("Please enter username:")
password = input( "Please enter password:")
for i in list:
if username==i['username'] and password==i['password']:
print("Login is successful")
count=3 #To jump out of the while loop
break # Jump out of the for loop
else:
b=b-1
a=a-1
print('Login failed, re-enter, remaining %s chances'%a )
count += 1
if b==0:
print('No chance!')
break
if count==3:
choice=input('Whether to try 3 more times, yes or no:')
a=3
if choice== 'yes' :
count=0
else:
print('Goodbye!')
break

--------------------------------- ------------------------------------

Guess you like

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