Page 170 - Information_Practice_Fliipbook_Class11
P. 170

print(j, end=' ')
                  spaces = spaces - 2
                  print()
          13.  Write a program to accept two numbers and display their LCM (Least Common Multiple).
         Ans.  # To find LCM
              num1 = int(input('Enter the first number  :  '))
              num2 = int(input('Enter the second number  :  '))
              for i in range(max(num1, num2), 1 + (num1 * num2)):
                  if i % num1 == i % num2 == 0:
                      lcm = i
                      break
              print('LCM of', num1, 'and', num2, 'is', lcm)
          14.  When the following code is executed, what output will be produced. Also, indicate which of the statements labelled s1,
              s2, s3, s4, and s5 will not get executed?
              counter = 1
              while counter <= 16:
                   if counter < 16:
                          print('counter: ', counter)   #s1
                   else:
                          break                         #s2
                          print('Stop')                 #s3
                   counter += 4                         #s4
              else:
                  print('Exit from loop')     #s5
         Ans.  counter: 1
              counter: 5
              counter: 9
              counter: 13
              Exit from loop
              Statements s2 and s3 will not get executed

          15.  When the following code is executed, what output will be produced. Also, indicate which of the statements labelled s1,
              s2, s3, s4, and s5 will not get executed?

              counter = 0
              while counter <= 16:
                   if counter < 16:
                          print('counter: ', counter)  #s1
                   else:
                           break                       #s2
                          print('Stop')                #s3
                   counter += 4                        #s4
              else:
                  print('Exit from loop')              #s5
         Ans.  counter: 0
              counter: 4




          156  Touchpad Informatics Practices-XI
   165   166   167   168   169   170   171   172   173   174   175