Created
January 20, 2015 18:59
-
-
Save CesarNog/7699e264ceb37277a05c to your computer and use it in GitHub Desktop.
Factorial function written in Python. To calculate the factorial of a non-negative integer x, just multiply all the integers from 1 through x. For example: factorial(4) would equal 4 * 3 * 2 * 1, which is 24. factorial(1) would equal 1. factorial(3) would equal 3 * 2 * 1, which is 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(n): | |
if n == 0: | |
return 1 | |
else: | |
return n * factorial(n-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment