Python Getting Started Practice _ Login

Source: Internet
Author: User

After learning simple conditional judgments and loops, do a little exercise and write a program about login.

USERNAME,PASSWD temporarily writes dead in the program, subsequent learning how to read from the file.

Program Requirements:

(1) Let the user enter the account number and password (input)

(2) Determine if the username and password are correct (if)

(3) Prompt xxx, welcome to login, today's date is XXX, program end (string formatting, placeholder)

(4) Wrong words prompt: Account/Password input error

(5) Enter a maximum of three times, if the input 3 times did not log in successfully, indicating too many failures (While-else,for-else)

(6) Need to determine whether the input is empty: User name, password cannot be empty, empty is also counted as error (strip)

1. First use while loop to complete

1 Import datetime 2 username = ' ran ' 3 passwd = ' 123456 ' 4 count = 0 5 today = Datetime.date.today () 6 while Count<3:7     uname = input (' Enter user name '). Strip () 8     pwd = input (' Please enter a password '). Strip () 9     if uname = = Username and pwd ==passwd:10
   
    print (' login succeeded, welcome%s, today's date is%s '% (uname,today) ') one         break12     elif uname = = ' or pwd = = ':         print (' username or password cannot be null ')     else:15         print (' User name or password input error ')     count + = 117 else:18     print (' Excessive number of failures ')
   

2, then use for loop to complete once

Press CTRL + C to copy the code<textarea></textarea>Press CTRL + C to copy the code

Python Getting Started Practice _ Login

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.