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

else:

                print("Given number is NOT a palindrome")
            Program 8

            Write a program that takes a number as an input and checks whether it is prime or not. Prime numbers are natural
            numbers that are divisible by only 1 and the number itself.
            Ans. '''

                 Objective: To check whether a number is a prime number
                 Input: num
                 Output: result whether it is prime or not
                 '''

                 num = int(input("Enter a Number: "))
                 upperLimit = num
                 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 9
            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=' ')

                                                                                                      Practical  373
   370   371   372   373   374   375   376   377   378   379   380