Page 239 - Computer Science Class 11 Without Functions
P. 239

6.  Rewrite the following code using while loop.
                  for sun in range(5):
                     for moon in range(3):
                             if sun**moon>=5:
                                  print(sun)
                             else:
                                  print(moon)
                    Now, when you have two codes that achieve the same functionality (one using the for  statement and the while
                  statement), which one will you prefer and why?
               7.  What will be the output produced on execution of the following code snippets: (chapt_11_unsolved.py)
                  (i)  x = 5
                     y = 2
                     while x >= y:
                         print(x, y, sep='#')
                         x = x - 1
                         y = y + 1
                  (ii)  for x in 'World Peace':
                       if x == ' ':
                           continue
                       else:
                           print(x, end = ' ')
                  (iii)  num = 5
                     while(True):
                         print(num)
                         num = num - 1
                         if num == 2:
                             break
               8.  What is the use of the pass statement in Python? Illustrate your answer with a suitable example.
            E.  Unsolved Programming Questions
               1.  Write a program to display the sum of first n natural numbers.
               2.  Write a program to accept 10 numbers and display the sum of only odd numbers.
               3.  Write a program that accepts as input the count of numbers (say, n) to be entered, followed by the numbers, and displays
                  the second largest number.
               4.   Write a program in Python that takes n as input from the user and prints first n elements of a Fibonacci sequence
                  0         1         1         2         3         5         8…………….
               5.   Write a Python Script to accept two numbers and display all prime numbers between those two numbers.
               6.   Write a program to accept a number and check whether it is a palindrome.
               7.   Write a program in Python to accept names and marks of 10 students and then display the following:
                  a.    Average Marks
                  b.    The student with the highest marks
                  c.    The student with the lowest marks

               8.   Write a program to accept the values of p and n as input from the user and then display the sum of given series:
                           3
                        2
                                      n
                              4
                  1-p+p -p +p - ...p
               9.   Write a program to check whether a number is a perfect number or not.
                  (Note: A perfect number is positive and is equal to the sum of its divisors.)


                                                                                              Looping in Python  237
   234   235   236   237   238   239   240   241   242   243   244