Last active
December 10, 2015 14:08
-
-
Save itsjef/4445521 to your computer and use it in GitHub Desktop.
Hàm tính tích của n số tự nhiên dương đầu tiên (n!)
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
#!/usr/bin/env python2.7 | |
def factorial(n): | |
ans = 1 | |
if n == 0 or n == 1: | |
ans = 1 | |
elif n < 0: | |
ans = 'no answer' | |
else: | |
for i in range(2, n+1): | |
ans *= i | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment