Thursday 19 September 2024

Practical - 69 - Write a program in python to input a number and calculate factorial of a number.

Practical - 69 - Write a program in python to input a number and calculate factorial of a number.


Ans:

n=int(input("Enter a number: "))

fact=1

if(n<0):

    print("Factorial can not be find of a negative number")

elif(n==0):

    print("Factorial of 0 is 1")

else:

    for i in range(1,n+1):

        fact=fact*i

    print("Factorial of",n,"is",fact)

 

Output:

Enter a number: -2

Factorial can not be find of a negative number


OR


Enter a number: 0

Factorial of 0 is 1


OR


Enter a number: 6

Factorial of 6 is 720

1 comment: