web counter
Develop a Python program to clearly understand the concept of recursion.

Develop a Python program to clearly understand the concept of recursion.

Input:

Output: # This program is to understand recursion in Python.

# Define a recursive function to calculate the factorial of a number
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n – 1)

# Calculate factorial of number 5
result = factorial(5)
print(“Factorial of 5 is “, result)

# Output: Factorial of 5 is 120

Prompt: Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
Develop a Python program to clearly understand the concept of recursion.

### Input:

### Output:
# This program is to understand recursion in Python.

# Define a recursive function to calculate the factorial of a number
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n – 1)

# Calculate factorial of number 5
result = factorial(5)
print(“Factorial of 5 is “, result)

# Output: Factorial of 5 is 120