Write a program to find factorial of a given number

 

PYTHON PROGRAM

Write a program to find factorial of a given number



"""

Write a program to find factorial of a given number.


"""

num=int(input("Enter a postive integer number:"))  #so first you have to take input from a user using int()and input()function here int()means the number whixh would you get it would be integer type

fact=1 #here take one variable fact=1

for i in range(1,num+1): #we have to run loop in which the value of will be 1 and it will increase after every loop and it will until value of num means num value times loop will run

fact=fact*i # here fact=1*1

                    #fact=1*2 because i=2 in second time loop

                    #fact=2*3

                    #fact=6*4

                    #fact=24*5 now loop will terminate

print(fact) #Now use print()function to show the factorial of the input number.

No comments:

Powered by Blogger.