For Loop
One, 1-100 odd
Method one: General value
for I in Range (1,101):
If I% 2==1:
Print (i)
Method Two: Using step size
for I in Range (1,101,2):
Print (i)
Two, 1-100 odd, 50-70 not printed
for I in Range (1,101):
If 50<=i <=70:
Continue
elif I 2 = = 1:
Print (i)
Third, login program, try to log in three times, success is terminated
_user= ' alon '
_passwd= ' [email& Nbsp;protected] '
for I in range (3):
User=input (' Username: ')
Passwd=input (' passwd: ')
if User==_user and PASSWD==_PASSWD:
Print (' Welcome to%s '%user)
Break
Else:
Print (' username or password is wrong, please reenter ')
while Loop
One , log in the program, try to log in three times, the success is terminated three times the hint has been tried several times. and asks if you want to continue trying
sum = 0
_user= ' alon '
_passwd= ' [email protected] '
while sum <3:
User=input (' Username: ')
Passwd=input (' [email protected]: ')
if User==_user and passwd==_passwd:
Print (' Welcome to %s '%_user)
Break
Sum + = 1
If sum ==3:
xuanze=input (' Do you want to continue? [y/n] ')
if Xuanze = = ' y ':
sum = 0
Else:
Print (' has tried several times ')
"Python Basics"--loop first knowledge