Python practice applet (1), python practice Applet
Question: Compile the login interface
- Enter user name and password
- Welcome information displayed after successful authentication
- Lock after three wrong attempts
1 #! /Usr/bin/env python3 2 #-*-coding: UTF-8-*-3 a = {'breakering ': 'dmc19930417', 'propfu ': 'snapshot 66666666'} # create a dictionary, which is equivalent to database 4 try: 5 d = open(' B .txt ') # Open the blacklist in Read mode. If the blacklist file exists, 6 TB t IOError: 7 d = open(' B .txt ', 'w') # create a blacklist file if the blacklist file is not saved. close () 9 d = open(' B .txt ') # after creation, read 10 for I in range (3 ): # allow the user to perform three attempts 11 n = input ('enter your name: ') 12 if n not in d. read (): # if the user name is not in the blacklist, 13 if n in. keys (): # If the user name is in the database, 14 For k in range (3): # allow the user to enter the password three times and try 15 m = input ('enter your password: ') 16 if m = a [n]: # If the username and password Match 17 print ('login successful! ') 18 break # login successful and exit loop 19 else: 20 print ('password error') # Otherwise the system prompts Password error to continue loop 21 if k = 2: # If the number of inputs reaches 3 times, 22 with open(' B .txt ', 'A') as c: # Open the blacklist and put the user in 23 c. write (n + '\ n') 24 print ('this user has been locked') 25 break # used to exit the External Loop 26 else: 27 print ('user name does not exist ') # If the user name is not in the database, the output user name does not exist 28 else: 29 print ("this account has been locked") # The user is in the blacklist, the user is locked for 30 break # The user jumps out of the External Loop.
The first write is incomplete!