Python Learning-First day

Source: Internet
Author: User

Start learning Python and start recording.

The first small program: Login system

Function: 1. Import user name and password by file name and password ~

2. User input user name and password

3, the user entered the user name to compare, first determine whether the user name is in the blacklist, if the blacklist is directly exit; if not in the blacklist to continue to enter the password, and then the user name and password with the correct user name password matching, matching through the display login success, matching failure prompt re-enter the password, Password input error three times to exit the system, lock the user name, blacklist.

Use of knowledge points: 1, file read and write operations. Minutes: Open file, read-only with R, open read and write content, with w+ or r+,w+ is append write, but each re-open will overwrite the contents of the original file. R+ is appended directly to the original file content.

2, List basic knowledge, dictionary basic knowledge

3, import the module, is the input password is not visible

Source:

#Author: QCG
info = open ('/home/me/python-study/20170913/info.txt ', ' R ') #导入用户名密码
Blanklist=open ('/home/me/python-study/20170913/blanklist.csv ', ' r+ ')
#username = input ("Please input username:")
#passwd = input ("Please input your Passqord:")
#创建用户名密码字典
For line in info:
User_list=line.split (', ')
I=0
dic_usr={}
While I<len (user_list)/2-1:
dic_usr[user_list[(2*i)]]=user_list[(2*i+1)]
I+=1
#print (DIC_USR)
Username = input ("Please input username:")
For line in Blanklist:
# Print (line)
If username in line:
Print ("Sorry,you is forbidden to Logn in")
Break
Count = 0
While count<3:
passwd = input ("Please input your password:")
If username in dic_usr and dic_usr[username]==passwd: #判断用户名是否在黑名单中, if not, match user name password ~
Print ("Welcome to Logn in")
Break
Else
Print ("Please try again~~~")
Count+=1
Else
Print ("You have try too Manay Times,byebye")
Blanklist.write (username)
Blanklist.write (', ')
Blanklist.close ()
Info.close ()

Loading attachments Tomorrow ~

Python Learning-First day

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.