Sunday, 23 January 2022

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

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

import math

 num = int(input("Enter the number:")) 

def fact(n): 

    return(math.factorial(n)) 

 

 f = fact(num) 

print("Factorial of", num, "is", f)

  

def checkPrime(x):

    for i in range(2, x):

        if num%i==0:

            return 1

 

p = checkPrime(num)

if p==1:

    print("\n" +str(num)+ " is not a Prime Number")

else:

    print("\n" +str(num)+ " is a Prime Number")