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)