1 #!/usr/bin/env python3
2
3 import sys #导入sys模块
4
5 user = 'mirck'
6 passwd = 'wzzx@123'
7 lockfile = 'lock.txt'
8
9
10 fobj = open(lockfile)
11 for nums in range(3):
12 username = input("username:")
13 password = input("password:")
14
15 for line in fobj.readlines():
16 if username == line.strip():
17 print ("%s User is locked" % (username))
18 sys.exit(1)
19 if username == user and password == passwd:
20 print ("Welcome Login")
21 break
22 else:
23 print ("There are %s other locking users" % (2 - nums))
24
25 else:
26 print ("%s User input time more than 3 times user lock" % (username))
27 fobj = open(lockfile, 'a+')
28 fobj.writelines(username + '\n')
29 fobj.close()
30
31 fobj.close()