Python learning experience-basic knowledge (i)

Source: Internet
Author: User

First, login verification

Requirements: Verify that the login username and password are correct, and that the login is locked after three unsuccessful logons.

Implementation method One:

I=0while i<3:    s=input (' Please enter user name: ')    d=input (' Please enter password: ')    if s== ' dage ' and d== ' 123456 ':        print (' Congratulations login successful! ')        break    Else:        print (' username or password is wrong, please enter ' again ')    I=i+1else:    print (' input more than three times, stopped input ')

Implementation method Two:

For I in range (3):    s=input (' Enter user name: ')    d=input (' Please enter password: ')    if s== ' dage ' and d== ' 123456 ':        print (' Congratulations login success! ')        Break    Else:        print (' username or password is wrong! ') else:    print (' Enter more than 3 times, stop login ')

Implementation method Three:

#name: username #pwd: User password #num: number of validations Def Denglu (name,pwd,num):    c=num for    i in range (num):        a=input (' Please enter user name: ')        b=input (' Please enter user password: ')        if A==name and b==pwd:            print (' Congratulations on your landing success! ')            Break        Else:            print (' User name or user password is wrong! ')            C=c-1            Print (' You have%d input chance '%c)    else:        print (' You have entered%d times incorrectly, suspend login! ') %num) Denglu (' Dage ', ' 123456 ', 3)

Note: The code can be reused as much as possible.

Python learning experience-basic knowledge (i)

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.