Python for loop learning - even and login authentication output of 1-100

Output even 1-100

Renderings:

Implementation code:

for i in range(2,101,2):
print(i,end = '\t')
if(i == 34):
print('\n')
if (i == 68):
print('\n')

Resolution:

for loop range (range) can specify three parameters, i.e., three parameters created list: starting number, the last digit, step (digital interval), the nature of the for loop is to create a list of numbers, I use list followed by the number assigned when the list the last number assigned to the i end of the cycle. Therefore, the even-numbered 1-100 is the start of the first number is 2, step 2, to the end 100 or 101 can be. If the starting position is set to 1, the end position is set to 100, for the odd-numbered 1-100. In order to facilitate the screenshot I was a three-line printing.

 

Login Authentication

Renderings:

 

Implementation code:

= _user "Mr.Zhu" 
_pass = "123456"
for I in Range (0,3):
User = INPUT ( "the User:")
password = INPUT ( "Password:")
IF (User password == == _user and _pass):
"! is available for purchase% S" Print (% the User)
BREAK
the else:
Print ( "at The username or password IS Wrong")
the else:
"! by you have have Wrong MANY Times and now you are Banned to the try" Print ()

Resolution:
first prepare the user information needs (you can create your own with a list of simple database)
for circulation, the number of cycles is three times as the user name and password at the same time will log the correct success and out of the loop (for limited circulation, are needed before ordained cycles, when the user must enter the correct execution to break out of the loop, otherwise the user will be asked to continue to input)
when an error occurs, the user inputs a total of three opportunities, three times all wrong for the end of the cycle, the outermost else that comes with the for loop will execute the else statement when else, when the for loop full circle jump (rather than break), a warning to unauthorized users.

Guess you like

Origin www.cnblogs.com/zhurs/p/11520781.html