python
Calculate the factorial of a number using python code
A recursive function is the best way to calculate the factorial of a number using Python.
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = 4
print("The factorial of", num, "is", factorial(num))
Was this helpful?
Similar Posts
- Calculate the square root of a number in python
- Python code to check if a given number exists in a list
- Calculate simple and compound interest in Python
- Python code to validate email address using regex
- Python Measure the execution time of small bits of Python code with the timeit module
- How to generate a random number in python using random module
- Check Armstrong Number using Python