Python Job 1

Source: Internet
Author: User

The user has three chances to log in, log in successfully, display the Welcome screen.

Three login failed, account locked, next logon failed.

Ideas:

1: Process Control: For or while loop, up to three detection purposes.

2: File operation.

Detect the document, once the input account name is found in the locked document, display lock, Login failed.

First time without optimized version code:

#_ *_coding:utf-8_*_times = 0 # initial number of 0Username = "Wuqiangroy" UserPassword = "123321" f = open ("Aaa.txt", "R") # Open AA in read mode a.txt files, if not created automatically. File_list = F.readlines () f.close () lock = [] #lock为一个列表. For i in file_list:line = I.strip ("\ n") lock.append (line) Else:while times < 3:username = Raw_input ("            Please enter the username: ") if username in Lock: #检测输入帐户名是否在lock中, if the display account is locked, then break jumps out of the loop.            Print "You have been locked!" Break password = raw_input ("Please enter your password:") if username = = Username and password = USERPASSW Ord:print "successfull!            Welcome Log in! " Break Else:print "Your username or password is wrong! Please enter again! "Times + = 1 print" You just has only%s shots! "% (3-times) Else:print" The only 3 time        s you used out and the account has been locked! "       f = open ("Aaa.txt", "w+") #以写入模式打开aaa. txt file f.write ("\ n") F.write (username) #三次机会输入错误 to write the entered name into the Aaa.txt file. F.close ()

  

Python Job 1

Related Article

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.