Page 102 - Computer - 8
P. 102

Computational Skills
            Mind Stretching

            1.  Identify and underline the errors in the code given below. Also, write the correct code.
               (a) # Program to display all numbers between 1 and 10 in decreasing order.
                   for num in range(1, 10, -1):
                   print(num)
               (b)  # Program to print the sum of numbers from 1 to 20.
                   sum = 1
                   num = 1
                   while num < 20:
                    sum = sum + num
                   print(“The sum of numbers from 1 to 20 = ” sum)

            2.  Write the output of the following code segments in Python:

               (a)  for count in range(2, 10):
                    print(count)
               (b)  prod = 1
                   num = 10
                   while  X >= 1:
                    prod = prod * num
                    num = num – 1
                     print(prod)



             Lab Work                                                                              Computational Skills


              Write the following in Python:
                (a)  Program to display the sequence 5, 8, 11, 14, … up to 76.

                (b)  Program to accept a number from the user and display its table.
                (c)  Program  to  accept  two  numbers  from  the  user  and  display  all  even  numbers  between  the  two
                    numbers in decreasing order.
                (d)  Program to calculate and display the sum of first 10 multiples of 3.
                (e)  Program to accept three numbers from the user and display all even numbers between the smallest
                    and largest numbers, excluding the multiples of the third number.



            DISCUSS
            DISCUSS                                                                                Communication Skills
             Which loop in Python offers more flexibility to be used in most situations? Discuss with your classmates.



           TEACHER’S DESK
           TEACHER’S DESK
           Explain to the students the use of different loops in different situations to create programs in Python.





              100
   97   98   99   100   101   102   103   104   105   106   107