For循环:

idname = 'a'
password = '1'

i=0
for i in range (3):
    id1 = input('input your id name>>')
    pass1 = input('input your password>>')
    if id1 == idname and pass1 ==password:
        print('welcome!')
        break
    else:
        print('id or password flase! try again')
        i += 1
else:
    print('your id is locked.')

 

While循环:

idname = 'a'
password = '1'
i = 0
while i < 3 :
    user1 = input("username>>")
    pass1 = input("password>>")
    if user1 == idname and pass1 == password:
        print("WELCOME!")
        break
    else:
        print("Username Or Password Invalid")
        i += 1
else:
    print('your id is locked')