Python practice applet (1), python practice Applet

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.