mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-21 21:27:36 +00:00
Some directories had a capital in their name [fixed]. Added a recursive factorial algorithm. (#763)
* Renaming directories * Adding a recursive factorial algorithm
This commit is contained in:
parent
48bba495ae
commit
df04d94543
13
maths/factorial_recursive.py
Normal file
13
maths/factorial_recursive.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
def fact(n):
|
||||||
|
"""
|
||||||
|
Return 1, if n is 1 or below,
|
||||||
|
otherwise, return n * fact(n-1).
|
||||||
|
"""
|
||||||
|
return 1 if n <= 1 else n * fact(n-1)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Shown factorial for i,
|
||||||
|
where i ranges from 1 to 20.
|
||||||
|
"""
|
||||||
|
for i in range(1,21):
|
||||||
|
print(i, ": ", fact(i), sep='')
|
Loading…
x
Reference in New Issue
Block a user