1 # Way 1:
2 user = "Andy"
3 passwd = "123456"
4
5 for i in range(3):
6 username = input("Username: ")
7 password = input("Password: ")
8
9 if username == user and password == passwd:
10 print("Welcome %s Login..." % user)
11 break
12 else:
13 print("Invalid Username or Password ! ")
14
15 else:
16 print("You have the max try..., please contact your system admin for help")
17
18
19 # Way 2:
20 user = "Andy"
21 passwd = "123456"
22 Auth_Pass = False
23
24 for i in range(3):
25 username = input("Username: ")
26 password = input("Password: ")
27
28 if username == user and password == passwd:
29 print("Welcome %s Login..." % user)
30 Auth_Pass = True
31 break
32 else:
33 print("Invalid Username or Password ! ")
34
35 if not Auth_Pass:
36 print("You have the max try..., please contact your system admin for help")