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