python basis - loop

 

 

 

Print out 1-100

1 i=0
2 while i<=100:
3     print(i)
4     i+=1
. 1  for I in Range (1,101 ): # iteration number between 1 and 101, [1,101)
 2      Print (I)
. 1 I = 0
 2  the while True:
 . 3      I + =. 1
 . 4      Print (I)
 . 5      IF I> = 100 :
 . 6          BREAK # ends the present cycle

 1-100 summation

1 i=0
2 j=0
3 while i<100:
4     i+=1
5     j=i+j
6     print(j)
Print even-1-100
1 i=0
2 while i<101:
3     i+=1
4     if (i%2)==0:
5         print(i)
1 for i in range(1,101):
2     if (i%2)==0:
3         print(i)
Print odd 1-100
1 for i in range(1,101):
2     if (i%2)!=0:
3         print(i)
1 i=0
2 while i<101:
3     i+=1
4     if (i%2)!=0:
5         print(i)

 1-100 print is not included in the numbers 20 to 60

. 1 I = 0
 2  the while I <100 :
 . 3      I + =. 1
 . 4      IF I> = 20 is and I <= 60 :
 . 5          Continue # skipped cycles satisfying the condition 
. 6      Print (I)
. 1  for I in Range (1,101 ):
 2      IF I> = 20 is and I <= 60 :
 . 3          Continue skipped cycles satisfying the condition # 
. 4 Print (I)

 1,2,3,4 print out any of the three different combinations of numbers

1 for i in range(1,5):
2     for j in range(1,5):
3         for k in range(1,5):
4             if (i!=j)and(i!=k)and(j!=k):
5                 print(i,j,k)

 

 

 

Guess you like

Origin www.cnblogs.com/xusin/p/11954132.html