Page 168 - Information_Practice_Fliipbook_Class11
P. 168

Ans.  22 110
            (xiv)  while(3>2):

                    print('Yes', end='')
                else:
                    print('Tried', end = '')
            Ans.  Infinite loop YesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYes …
            (xv)  for i in range(1, 5):

                    for col in range(6, 10):
                        print(i*col, end=' ')
                print()
            Ans.  6 7 8 9 12 14 16 18 18 21 24 27 24 28 32 36

           6.  What will be the output produced on the execution of the following code snippet:
              for i in range(1,5):
                  pass
                  print(i, end='')
              print('NO OUTPUT')
         Ans.  1234NO OUTPUT
          7.  Rewrite the following program after removing the errors. Underline each correction made.
              txt = 'Good Morning'
              for s in range(txt):
              print(s)
         Ans.  txt='Good Morning'
              for s in (txt):
                  print(s)
           8.  Differentiate between for loop and while loop.
         Ans.  for loops: The number of iterations is known in advance.

              while loops: The body of the while loop is executed until the test condition remains True.
           9.  What will be the output produced on execution of the following program?
              '''
              Objective: To count the number of spaces in a input sentence
              Inputs:
                  sentence : a string
              Output:
                  count : Number of spaces
              '''
              sentence = input('Enter a sentence: ')
              count = 0
              for char in sentence:
                  if char == ' ':
                      count += 1
              else:
                  print('The number of spaces: ', count)
         Ans.  Enter a sentence: Honesty is the best policy
              The number of spaces:  4




          154  Touchpad Informatics Practices-XI
   163   164   165   166   167   168   169   170   171   172   173