0% found this document useful (0 votes)
12 views

Recursive Fun Python

The document describes a Python program that uses a recursive function to calculate factorials. The program defines a fact() function that takes a number as a parameter and recursively calls itself to calculate the factorial, returning the result. It then prompts the user for a number and prints out the factorial of the input number.

Uploaded by

ABHAY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Recursive Fun Python

The document describes a Python program that uses a recursive function to calculate factorials. The program defines a fact() function that takes a number as a parameter and recursively calls itself to calculate the factorial, returning the result. It then prompts the user for a number and prints out the factorial of the input number.

Uploaded by

ABHAY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# Learning Python programming Langauge

# This program will illustrate how Recursive function call with argument
# We have defined fact() function with one argument.
# we gave call to fact() with user input
# This will calculate the factorial of given number using recursive function
# Output has been attached with it.

def fact(num):
if num == 0 :
result = 1
else :
result = num * fact (num - 1)
return result
print("\n\tEnter value for factorial == ",end="")
n1 = eval(input())

print("\n\tFactorial of {} = ".format(n1),fact(n1))

==================================================================
=========================
Output:
F:\Python\Programs>py RecursiveFunPython.py

Enter value for factorial == 3

Factorial of 3 = 6

F:\Python\Programs>py RecursiveFunPython.py

Enter value for factorial == 7


Factorial of 7 = 5040

F:\Python\Programs>py RecursiveFunPython.py

Enter value for factorial == 5

Factorial of 5 = 120

F:\Python\Programs>
==================================================================
=========================

You might also like