---
title: "Implement a function to find the factorial of a given number using recursion."  
description: "Implement a function to find the factorial of a given number using recursion."  
author: "Steilla Mitchel"  
published: 2023-06-18  
updated: 2023-06-19  
canonical: https://www.mindstick.com/forum/158760/implement-a-function-to-find-the-factorial-of-a-given-number-using-recursion  
category: "python"  
tags: ["python", "programs"]  
reading_time: 2 minutes  

---

# Implement a function to find the factorial of a given number using recursion.

Implement a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) to find the factorial of a given number using recursion.

## Replies

### Reply by Aryan Kumar

Sure, here is a Python function to find the factorial of a given number using recursion:

Python

```plaintext
def factorial(number):
  """
  Finds the factorial of a given number using recursion.

  Args:
    number: The number to find the factorial of.

  Returns:
    The factorial of the number.
  """

  if number == 0:
    return 1
  else:
    return number * factorial(number - 1)

if __name__ == "__main__":
  number = 5
  factorial_value = factorial(number)
  print(factorial_value)
```

This function works by first checking if the number is 0. If it is, then the function returns 1. Otherwise, the function recursively calls itself, passing in the number minus 1. The function then multiplies the result of the recursive call by the number and returns the result.

To run the function, you can save it as a Python file and then run it from the command line. For example, if you save the function as `factorial.py`, you can run it by typing the following command into the command line:

Code snippet

```plaintext
python factorial.py
```

This will print the factorial of the number to the console.

Here is an example of the output of the function:

Code snippet

```plaintext
$ python factorial.py
120
```

As you can see, the output of the function is 120, which is the factorial of 5.


---

Original Source: https://www.mindstick.com/forum/158760/implement-a-function-to-find-the-factorial-of-a-given-number-using-recursion

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
