python--Landing Interface Design (cyclic method)

Source: Internet
Author: User

Recently re-organized the Landing interface design program, feel the previous code did not comment, so that the garden of other children's shoes to read more laborious. There are no flowchart and program run instructions.

1. Flowchart

2.user_file.txt&lock_file.txt File Contents

(1) User_file.txt

Abel 123
Bbel 1234
Cbel 123456

(2) Lock_file.txt

Dbel

3. Program Operation instructions

(1) Enter the user name, the program comparison lock_file.txt. If there is a prompt that the user has been locked out, exit the program.

(2) The program finds whether the user name is in User_file.txt, if the user is not prompted, and exits the program.

(3) The user entered the password, entered three consecutive times, the password is correct. Prompt to welcome and exit the program.

(4) password continuous input error 3 times, prompting the user has been locked, and the user name is written to Lock_file.txt. Exits the program.

4. Program code

1 ImportOS2 3User_file = open ('Use_file.txt','R')#Open User_file.txt4User_list = User_file.readlines ()#load the contents of User_file.txt into memory at once5User_file.close ()#Close User_file.txt6 7  whileTrue:8Lock_file = open ('Lock_file.txt','r+')#Open Lock_file.txt9Lock_list = Lock_file.readlines ()#loading content from Lock_file.txt into memoryTenLock_file.close ()#Close Lock_file.txt One  ALogin_success = False#set the marker bit to jump out of the loop -user_name = input ('Please enter your name:'. Strip ())#Enter user name -      forLine1inchlock_list: theline1 = Line1.split ()#read information from Lock_file.txt to line1 -         ifUser_name = = Line1[0]:#If the user name prompts for information in line1 and exits the entire program -             Print("I'm sorry! Your user name is already locked, please contact the webmaster. ") - exit () +      forLine2inchuser_list: -Line2 = Line2.split ()#read information from User_file.txt to Line2 +         ifUser_name = = Line2[0]:#If the user name enters a for loop in line2 (enter password three times error lock) A              forIinchRange (3):#counter, record password input error number atPassword = input ('Please enter your password'. Strip ())#Enter Password -                 ifPassword = = Line2[1]:#if password in line2[1], display the welcome message and exit the entire program -                     Print("Welcome to%s login Abel website!"%user_name) -Login_success =True -                      Break -             Else:#Password input error more than 3 times, the user name is written to Lock_file.txt inf = open ('Lock_file.txt','a') -F.write ('%s\n'%user_name) to f.close () +                 Print("Enter the wrong password 3 times, your user%s is locked, please contact the webmaster. "% user_name)#prompt the user is locked and exits the entire program -Login_success =True the                  Break *             iflogin_success: $                  BreakPanax Notoginseng         Else:#The user name is not in Line2, prompting the user name does not exist. and quit the whole program . -             Print("the user name you entered does not exist, please re-enter or register") the exit () +     iflogin_success: A          Break

python--Landing Interface Design (cyclic method)

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.