Page 76 - Touchcode_C6_Flipbook
P. 76

Subject Enrichment
                    Example 1: To print a statement six times using the 'for' loop.


                  Pseudocode:
                  Program Start
                  for a in range 1 to 6

                         display 'I want to play'
                  Program End
                                                                                                       Subject Enrichment

                    Example 2: To print all the odd numbers from a list using for loop.

                  Pseudocode:

                  Program Start
                  list1 = [12, 25, 8, 50, 75, 30]
                  for a in list1
                         if a % 2!= 0
                         print(a, end = ' ')
                  Program End
                  Note: A list is a collection of ordered, changeable (mutable) elements, where duplicates
                  are allowed. Lists are commonly used in programming to store multiple values in a single
                  variable.
                  end = ' ' , is used to print output on the same line after space.                    Subject Enrichment


                    Example 3: To print all the even numbers from the given list by using 'for' loop.

                  Pseudocode:
                  Program Start

                  list2 = [14, 25, 8, 50, 75, 30]
                  for a in list2
                         if a % 2 == 0
                         print(a, end = ' ')
                  Program End

                    Coding           uiz   01                                                            Critical Thinking


                      Fill in the blanks.

                      a.  A  ............... loop  statement repeatedly  executes a statement as long  as the
                          condition remains true.
                      b.  A  ............... loop executes for a specific number of times.






                   74     Touchcode-VI
   71   72   73   74   75   76   77   78   79   80   81