Skip to content

Commit 503e79d

Browse files
committed
Factorial in python
1 parent 74dd9f0 commit 503e79d

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

Factorial/Python/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### Factorial
2+
3+
http://en.wikipedia.org/wiki/Factorial
4+
5+
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
6+
7+
The value of 0! is 1, according to the convention for an empty product.
8+
![Factorial of 5](http://upload.wikimedia.org/math/9/3/9/939c013423574cad70f33eaa7dd68f0c.png)
9+
10+
Definition:
11+
![Factorial Definition](http://upload.wikimedia.org/math/a/9/1/a91da51a80ac8291d8dbcc4cb77c0936.png)
12+
13+

Factorial/Python/factorial.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def factorial_recursive(num):
2+
"""returns the factorial of num using a recursive method."""
3+
return 1 if num == 0 else num * factorial_recursive(num - 1)

Factorial/Python/factorial_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import factorial
2+
3+
print factorial.factorial_recursive(0)
4+
print factorial.factorial_recursive(1)
5+
print factorial.factorial_recursive(5)

0 commit comments

Comments
 (0)