Wu Yuxiong - born naturally PYTHON3 development of learning: Loops

= 100 n- 
 
SUM = 0 
counter =. 1
 the while counter <= n-: 
    SUM = SUM + counter 
    counter + =. 1 Print ( " . 1 to the sum of% d:% d " % (n-, SUM))
 
1 = var
 the while var == 1:   # expression is always to true 
   NUM = int (the INPUT ( " Enter a number: " ))
    Print ( " the number you enter is: " , NUM) 
 
Print ( " ! Good BYE " )
= COUNT 0
 the while COUNT <5 :
    Print (COUNT, " less than 5 " ) 
   COUNT = COUNT +. 1
 the else :
    Print (COUNT, " greater than or equal to 5 " )
1 = Flag the while (Flag): Print ( ' Welcome to the rookie tutorial! ' ) Print ( " Good BYE! " )
 

 
for <variable> in <sequence>:
    <statements>
else:
    <statements>
= sites [ " Baidu " , " Google " , " Runoob " , " Taobao " ]
 for Site in sites:
     IF Site == " Runoob " :
         Print ( " ! newbie tutorial " )
         BREAK 
    Print ( " loop data " + Site)
 the else :
     Print ( " no cyclic data! ")
print("Complete the cycle! " )
for Letter in  ' Runoob ' :      # first instance 
   IF Letter == ' B ' :
       BREAK 
   Print ( ' current letters: ' , Letter) 
  
var = 10                     # the second instance 
the while var> 0:              
    Print ( ' profit variable value: ' , var) 
   var = var -1
    IF var ==. 5 :
       BREAK 
 
Print ( " Good BYE! " )
for Letter in  ' Runoob ' :      # first instance 
   IF Letter == ' o ' :         # alphabet skipped when the output o 
      Continue 
   Print ( ' the current letter: ' , Letter) 
 
var = 10                     # the second instance 
the while var> 0:               
   var = var -1
    IF var ==. 5:              # variable output is skipped 5 
      Continue 
   Print ( ' the current variable values: ' , var)
 Print ("Good bye!")
for n- in Range (2, 10 ):
     for X in Range (2 , n-):
         IF n-% X == 0:
             Print (n-, ' equal ' , X, ' * ' , // n- X)
             BREAK 
    the else :
         # loop elements not found 
        Print (n-, ' is a prime ' )

 

Guess you like

Origin www.cnblogs.com/tszr/p/10963272.html