Development environment: Windows
Editor: Pycharm
Python Environment: 3.6
Basic requirements: Write a login
Basic ideas:
1. Define user and password
2. Define the number of logins
3, using while loop to achieve the number of judgments
4. While loop nesting if else loop to implement the user name and password verification, if successful, display the login success, if the failure continues to log in, while the count part plus 1;
code example:
#!/usr/bin/env python#_*_coding:utf-8_*_#author pengimport getpassusername= "Admin" password= "admin" count=0print ('----*****web Management System * * * * *-----') while count<3: login_ Username=input ("Input your username:") login_password=input ("Input your password: ") if login_username ==username and login_password== Password: print ("Welcome to login: %s" %login_username) break elif login_username != username or login_password!=password: print ("% s time landing failed, please re-login! " %count) count +=1 if count==3: print ("You have entered the error 3 times to temporarily lock your users") breakprint ('----*****web Management System Exit * * * *-----')
Test results:
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe c:/users/administrator/pycharmprojects /s14/pc.py----*****web Management System * * * * * * *-----Input your username:useinput your password:www the No. 0 time landing failed, please re-login! Input your username:wwwinput your password:222 1th time login failed, please re-login! Input your username:wwwinput your password:eee 2nd time login failed, please re-login! You have entered the error 3 times to temporarily lock your user----*****web management system EXITS * * * *-----entered correctly: C:\Users\Administrator\AppData\Local\Programs\Python\ Python35\python.exe c:/users/administrator/pycharmprojects/s14/pc.py----*****web Management System * * * * * * *-----input your username: Admininput your password:admin welcome you to login: admin----*****web Management System QUIT * * * *-----
Summary and optimization here only need to determine the password and user name is correct, incorrect certainly can not login so only with else on the same time that the login count print is the count value, the initial value is starting from 0, the count should be starting from 1, the part is not annotated, and needs to be optimized later.
Python Basic Practice (i) Impersonate user login