Python Operations Development Practice--day1

Source: Internet
Author: User

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

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.