Assignments for the first week of Python learning-user simulated login, python --
Job Requirements:
(1) The user enters the account password for login
(2) Save User information in the file
(3) The user is locked after three wrong passwords are entered.
1 #! /Usr/bin/env python 2 # _ * _ conding: UTF-8 _ * _ 3 4 username = "gx" # login name 5 password = "123" # password 6 count = 0 7 8 p = open ("login.txt", "r ") 9 file_list = p. readlines () 10 p. close () 11 lock = [] # blacklist 12 13 name = input ("Enter username:") 14 for I in file_list: 15 lock. append (I) 16 if name in lock: 17 print ("The user has been locked, please contact the admin") # judge that The name is not in the blacklist 18 else: 19 if name = username: 20 while Count <:21 pwd = input ("Enter passwod:") 22 if name = username and pwd = password: 23 print ("Welcome % s! "% Name) 24 break # enter the correct name and password to log on and end 25 else: 26 print (" Sorry password is incorrect please re-enter ") 27 count ++ = 128 else: 29 print ("Paswword error three times, has been locked, please contact the admin") 30 p = open ("login.txt", "w + ") 31 n = ["% s" % name] 32 p. writelines (n) 33 p. close () 34 else: 35 print ("Username does not exist, please re-enter ")View Code