Monday, 24 January 2022

Write a Python Program to Check if given number is prime or not. Also find factorial of the given no using user defined function.

Slip 24 Q 1

CODE :

class factorial():
    def __init__(self,num):
        self.num=num
        factnum=1
        if self.num<0:
            print("Sorry, factorial does not exist for negative numbers")
        elif self.num==0:
            print("The factorial of 0 is 1")
        else:
            for i in range(1,num+1):
                factnum=factnum*i
            print('The factorial of {} is {} factorial'.format(num,factnum))

num = int(input("Enter a number: "))
if num > 1:
    for i in range(2,num):
        if (num % i) == 0:
            print(num,"is not a prime number")
            print(i,"times",num//i,"is",num)
            break
    else:
        print(num,"is a prime number")
else:
   print(num,"is not a prime number")

factorial(num)

OUTPUT :



No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...