First, the script function
Login interface
-Enter user name, password
-User name, password is empty, prompt
-Wrong three times lock
-After successful authentication, display welcome login information
Second, flow chart
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/25/wKioL1droTiiZSgUAADPxDw7k7o037.png-wh_500x0-wm_3 -wmp_4-s_4149469530.png "title=" Day1.png "alt=" Wkiol1drotiizsguaadpxdw7k7o037.png-wh_50 "/>
Third, Python code
[email protected] day1]# cat login.py
#!/usr/bin/env python
Import Sys
Username = ' Hanyun '
Password = ' hanyun123 '
Retry_count = 0
While True:
user = Raw_input (' Username: '). Strip ()
If len (user) = = 0:
print ' Username cannot be empty! '
Continue
passwd = Raw_input (' Password: '). Strip ()
If Len (passwd) = = 0:
print ' Password cannot be empty! '
Continue
#handle the username and passwd empty issue
#going to the loging Verificaiton part
If user = = Username and passwd = = password:
print ' Welcome%s login Our system! '% user
Break
Else
Retry_count + = 1
print ' wrong username or password,you has%s more chances! '% (3-retry_count)
if Retry_count = = 3:
print ' Your username is locked! '
Sys.exit ()
Iv. function Demonstration
[email protected] day1]# python login.py
Username:fdsaf
Password:cdsaf
Wrong username or password,you has 2 more chances!
Username:ada
Password:cdfd
Wrong username or password,you has 1 more chances!
Username:adfsa
password:333
Wrong username or password,you has 0 more chances!
Your username is locked!
[email protected] day1]# python login.py
Username:afc
Password:123
Wrong username or password,you has 2 more chances!
Username:hanyun
Password:hanyun123
Welcome Hanyun Login Our system!
[email protected] day1]# python login.py
Username:
Username cannot be empty!
Username:fdsfa
Password:dsf
Wrong username or password,you has 2 more chances!
Username:aa
Password:
Password cannot be empty!
Username:
This article from "Hanyun.fang" blog, reproduced please contact the author!
Python Operations Development Practice--day1