Python Writing Login interface
First, the demand
To write the login interface:
1. Enter the user name and password to log in
2. Incorrect three-time lock account
3. Next login or Last account, prompt lock, direct exit (use to read and write files)
4. Success after successful display of login
Second, the demand flow chart
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/8E/BB/wKiom1jKQvLxL28JAABq24LasGA863.png "title=" day1--login interface. png "alt=" Wkiom1jkqvlxl28jaabq24lasga863.png "/>
Third, code example
Example 1:#!/bin/bash/env python#_*_ coding:utf-8 _*_#python version:3.6 "Writing the Login interface: 1. Enter the username and password to log in 2. Wrong three times to lock the account 3. Next login or Last account, prompt lock, Direct exit (use file read/write) 4. Success Post Login Success "#lock定义为锁定文件lock = " e:/python_learn/day1/ Lock "#account定义为账户文件account = e:/python_learn/day1/account" #计数器count = 0# identifier flag = 1# defines the lock user list as empty lock_user = [] #打开锁定文件 and reads the locked account F1 = open (lock, ' r ') lock_file = F1.readlines () F1.close () #循环锁定账户, append the account to the Lock_user list for i in lock_file: i = i.strip (' \ n ') lock_user.append (i) #打开账户文件 and reads the user and password F2 = open ( Account, ' R ') Account_file = f2.readlines () f2.close () while true: name = input ("Input your name:") passwd = input ("input Your password: ") &nBSP; #如果输入的账户在锁定用户列表中, exit Loop; if name in lock_user: print ("user is lock!") break else: #否则计数器加count +1 count += 1 #如果count大于2, that is, wrong three times if count > 2: Print ("Error three times") #将账户添加到锁定账户中 with open (lock, ' a ') as f: f.write ("\ n" + name)            &NBsp;break #如果count小于2, else: #循环输入的用户名和密码, is it the same as the inside of the account file for i in account_file: n1,p1 = i.strip (). Split () if name == n1 and passwd == p1: print ("welcome login!! ") #如果账户密码一样, flag marked as true flag = True #如果输入账户密码和文件存储的不一样, jump out of this loop else: #跳出本次循环 continue #如果flag标识为True, exit the entire cycle if flag is true: break Example 2:# !/bin/bash/env python#_*_ coding:utf-8 _*_#python version:3.6lock = "E:/Python_ Learn/day1/lock "account = " E:/python_learn/day1/account "Count = 0flag = 1lock_ User = []f1&nbsP;= open (lock, ' R ') Lock_file = f1.readlines () f1.close () for i in lock_file: i = i.strip (' \ n ') lock_user.append (i) F2 = open ( Account, ' R ') Account_file = f2.readlines () f2.close () while true: name = input ("Input your name:") passwd = input ("input Your password: ") if name in lock_user: print ("user is lock!") break else: count += 1 for i in account_file: n1, p1 = i.strip (). Split () if name == n1 and passwd == p1: print ("welcome login!!") flag = True else: continue if flag is true: break else: if count > 2: print ("Error three times") with open (lock, ' a ') as f: &nBsp; f.write ("\ n" + name) break
This article is from the "506554897" blog, please be sure to keep this source http://506554897.blog.51cto.com/2823970/1907262
Python Writing Login interface