euler/e020.py
Correl Roush 12c5dd7875 Documented each exercise, and placed executable code in a main() function.
git-svn-id: file:///srv/svn/euler@63 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
2010-05-04 18:21:07 +00:00

25 lines
478 B
Python

"""Find the sum of digits in 100!
n! means n (n 1) ... 3 2 1
Find the sum of the digits in the number 100!
"""
# Could use math.factorial, but that takes the fun out of it, doesn it
def factorial(n):
f = n
i = n - 1
while i > 1:
f = f * i
i = i - 1
return f
def main():
f = str(factorial(100))
sum = 0
for c in f:
sum = sum + int(c)
print 'Sum of digits in 100!:', sum
if __name__ == '__main__':
main()