Page 507 - Computer Science V2.0 Class 11
P. 507

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

                                 break
                         else:
                             print(num, 'is a prime number')

                     num = int(input("Enter a number to check for prime: "))

                     checkPrime(num)
                 Program 9: Write a function fibonacci(num) that takes num as an input and prints the fibonacci series until num
                 terms. Invoke the function to print the fibonacci series for the user-entered nth term.

                 Ans. def fibonacci(num):
                         '''

                         Objective : To calculate the fibonacci series
                         Input Parameter : num - numeric value
                         Return Value : None
                         '''
                         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=' ')


                     num = int(input("Enter a number: "))
                     print("The fibonacci series is: ")
                     fibonacci(num)

                 Program 10: Write a Python program that accepts two numbers from the user and displays their greater common
                 divisor (GCD) and least common multiple (LCM).


                 Ans. def GCD(num1,num2):
                         '''
                         Objective : To calculate the GCD of 2 numbers
                         Input Parameters : num1,num2 - numeric value

                         Return Value : gcd - numeric value


                                                                                                           Practical  493
   502   503   504   505   506   507   508   509   510   511   512