Dayly programing (Project Euler:#20)
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/python | |
from math import factorial | |
def digit_sum(num,sum=0): | |
if num > 0: | |
num,sum = int(num / 10), sum + (num % 10) | |
return digit_sum(num,sum) | |
else: | |
return sum | |
print(digit_sum(factorial(100))) | |
#=>648 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment