Created
August 8, 2016 05:48
-
-
Save brainyfarm/33ef6a8b6a4ab077a24283423166be13 to your computer and use it in GitHub Desktop.
FreeCodeCamp Factorialize a number (Python)
This file contains hidden or 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
| """ | |
| 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