Page 352 - Information_Practice_Fliipbook_Class11
P. 352

for i in range(2, num):

               if num % i == 0:

                 print('Not a prime number, because',num, '=', i, '*', num // i)
                 #i divides num
                 break

               else:

                 print(num, 'is a prime number')
         Program 22: Write a program that takes a number num as an input and prints the fibonacci series until num terms.


        Ans. '''
             Objective: To calculate the fibonacci series till the upper limit

             Input: num - upper limit
             Output: Fibonacci series

             '''
             num = int(input("Enter a Number : "))
             print("The FIBONACCI SERIES IS : ")

             x = 0

             y = 1
             if num == 1:
                 print(x)

             else:

                 print(x,y, end=' ')
                 for i in range(2,num):
                     z = x + y

                     x = y

                     y = z
                     print(z, end=' ')
         Program 23: Write a program that accepts two numbers from the user and displays their greater common divisor
         (GCD) and least common multiple (LCM).


        Ans. '''
             Objective: To calculate GCD and LCM of 2 numbers

             Input: num1,num2

             Output: GCD,LCM
             '''

             num1 = int(input("Enter first number : "))



          338  Touchpad Informatics Practices-XI
   347   348   349   350   351   352   353   354   355   356   357