Python Program to Find Factorial of Number Using Loop Function

here you’ll get a python program to seek out factorial of variety mistreatment for and whereas loop.

Factorial of variety is calculated by multiplying it with all the numbers below it ranging from one.

For example factorial of four is twenty-four (1 x two x three x 4).

Below program takes variety from the user as associated input and realize its factorial.

Python Program to seek out Factorial of variety

num = int(input("enter a number: "))
 
fac = 1
 
for i in range(1, num + 1):
	fac = fac * i
 
print("factorial of ", num, " is ", fac)

Output

enter a number: 5
factorial of 5 is 120

Using While Loop

num = int(input("enter a number: "))
 
fac = 1
i = 1
 
while i <= num:
	fac = fac * i
	i = i + 1
 
print("factorial of ", num, " is ", fac)

Output

enter a number: 4
factorial of 4 is 24

Comment below if you’ve got any queries associated with on top of python factorial program.

Leave a Comment

error: Alert: Content is protected!!