Skip to content

Instantly share code, notes, and snippets.

@brainyfarm
Created August 8, 2016 05:48
Show Gist options
  • Save brainyfarm/33ef6a8b6a4ab077a24283423166be13 to your computer and use it in GitHub Desktop.
Save brainyfarm/33ef6a8b6a4ab077a24283423166be13 to your computer and use it in GitHub Desktop.
FreeCodeCamp Factorialize a number (Python)
"""
Return the factorial of the provided integer.
If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.
Factorials are often represented with the shorthand notation n!
For example: 5! = 1 * 2 * 3 * 4 * 5 = 120
"""
def factorial(n):
result = 1
if(n == 0):
return 1
else:
while(n >= 1):
result *= n
n -= 1
return result
print factorial(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment