This article mainly implements a simple login program, the default is to give an account password, put out the code to write and the process encountered problems.
----------------------------------------requirements are as follows:
Username
passwd
Let the user enter the account and password, enter the user and password to enter the correct words
prompt you xxx, welcome login, today's date is XXX, program end
Error, prompt account/Password input error
Enter up to 3 times, and if you enter 3 times, you are not logged in successfully, and the number of failed prompts is too large.
You need to determine if the input is empty, input null is also counted as an input error once
---------------------------------
The main problems encountered in the process are:
1. The Strip () method is required to determine that the input is empty
2. When printing the date, you need to format the%s in string format. The first time I used the%d format, the error format is incorrect
The code is as follows:
import datetimecount =0while count<3:username = input ("Username:" PWD = input ("Password:") Dayt = Datetime.date.today () #print (Dayt) if username.strip () = = "or pwd.strip () = = "": Print ("Your input is null,please input again!") Count=count+1 Continue elif Username = = "Julie" and pwd = = "123456": Print ("%s, welcome login, today's date is:%s, program end"% (US Ername,dayt)) Break Else:print ("Account/Password input error") Count = Count + 1else:print ("You have tried 3 Tim ES, the user has been locked! ")
Beginner Python3-Write a login program