Factorial – Python Lab Program

This is a simple program to find the factorial of a given number.

This program uses recursive function “factorial(x)”. (Example implementation of a recursive function in python).

def factorial(x):
"""This is a recursive function to find the factorial of an integer"""
if x == 1:
return 1
else:
return (x * factorial(x-1))

num = int(input("Enter the number of terms "))
print("The factorial of", num, "is", factorial(num))

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.