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

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?
              01 counter = 1
              02 while counter <= 16:
              03      if counter < 16:
              04             print('counter: ', counter)   #s1
              05      else:
              06             break               #s2
              07             print('Stop')                         #s3
              08      counter += 4         #s4
              09 else:
              10     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?

              01 counter = 0
              02 while counter <= 16:
              03      if counter < 16:
              04             print('counter: ', counter)   #s1
              05      else:
              04     if ch.isalpha():6            break             #s2
              07             print('Stop')    #s3
              08      counter += 4    #s4
              09 else:
              10     print('Exit from loop')   #s5
         Ans:  counter: 0
              counter: 4
              counter: 8
              counter: 12
              s3 and s5 will not get executed


         232   Touchpad Computer Science-XI
   229   230   231   232   233   234   235   236   237   238   239