Skip to content

Instantly share code, notes, and snippets.

@CesarNog
Created January 20, 2015 18:59
Show Gist options
  • Save CesarNog/7699e264ceb37277a05c to your computer and use it in GitHub Desktop.
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.
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