The first day of getting started with python. The code written by the instructor ., Python instructor

Source: Internet
Author: User

The first day of getting started with python. The code written by the instructor ., Python instructor

#! /Uer/bin/env python # _ * _ coding: UTF-8 _ * _ import sysretry_limit = 3retry_count = 0account_file = 'accounts.txt 'lock _ file = 'account_lock.txt' while retry_count <retry_limit: # username = raw_input ('\ 033 [32; Username: \ 033 [0m') within three cycles # Enter the username lock_check = open (lock_file) # Open the locked file for line in lock_check.readlines ():
Line = line. split () # Compare the cyclic lock file with the user name entered if uesrname = line [0]: # determine the user name entered by the user and the first element of the User Name of the lock file = sys. exit ('\ 031 [31; User % s is locked! \ 033 [0m' % username) password = raw_input ('\ 033 [32; Password: \ 033 [0m') # enter pass f = file (account_file, 'r + ') match_flag = False for line in f. readlines (): # loop acc file, user, password = lin. strip ('\ n '). split () # split the accounts file and filter the line break, assign the value to the user, and convert it to the list with pss. if username = user and password = password: # judgment: the entered use is equal to the user in acc and the entered pss is equal to the pss print ('match! '), Username match_flag = True break f. close () if match_flag = False: # The flag is interpreted and does not match by default. # Determine whether the user and pass entered by the user match the file. If they do not match the file, the loop continues. If they match the file, the system exits. Print 'user unmatched! 'Retry_count + = 1 else: print ('welcom to in feifei blog system! ') Else: print ("You account is locked! ") F = file (lock_file, 'AB') f. write (username) f. close ()

Job:
Write login interface

Enter user name and password

Welcome information displayed after successful authentication


Lock after three wrong attempts

 

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.