Page 435 - CITS - Computer Software Application -TT
P. 435

COMPUTER SOFTWARE APPLICATION - CITS




           7  square = 0
           8
           9  # Creating an empty list
           10 squares = []

           11
           12 # Creating a for loop
           13 for value in numbers:
           14 square = value ** 2
           15 squares.append(square)

           16 print(“The list of squares is”, squares)
           Output:
           The list of squares is [16, 4, 36, 49, 9, 25, 64, 100, 36, 1, 81, 4]


            Control Statements, String Manipulation, Lists, Tuple, sets


           Python Loop Control Statements

           Loop control statements change execution from their normal sequence. When execution leaves a scope, all
           automatic objects that were created in that scope are destroyed. Python supports the following control statements.

           Python Continue
           It returns the control to the beginning of the loop.
           •  Python3

           # Prints all letters except ‘e’ and ‘s’
           for letter in ‘geeksforgeeks’:
               if letter == ‘e’ or letter == ‘s’:
                   continue
               print(‘Current Letter :’, letter)

           Output:
           Current Letter : g

           Current Letter : k
           Current Letter : f
           Current Letter : o
           Current Letter : r
           Current Letter : g

           Current Letter : k
           Python Break
           It brings control out of the loop.










                                                           422

                             CITS : IT&ITES - Computer Software Application - Lesson 120 - 137
   430   431   432   433   434   435   436   437   438   439   440