- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Find Factorial of Number Using Recursion in Python?
Factorial of a number is product of all numbers from 1 to that number.
A function is called a recursive function if it calls itself.
In following program factorial() function accepts one argument and keeps calling itself by reducing value by one till it reaches 1.
Example
def factorial(x): if x==1: return 1 else: return x*factorial(x-1) f=factorial(5) print ("factorial of 5 is ",f)
Output
The result is
factorial of 5 is 120
Advertisements