Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created November 24, 2011 20:02
Show Gist options
  • Select an option

  • Save jakedobkin/1392176 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1392176 to your computer and use it in GitHub Desktop.
Euler 20
# set initial variable to hold the number we want to factorial
initial = 100
print initial,"! is equal to"
# do the factorial
i = initial
while (i > 0):
initial = initial * i
i = i - 1
# convert factorial to string, cut and add up the digits, print answer
sum=0
initial = str(initial)
while (i < len(initial)):
x = initial[i:i+1]
x = int(x)
sum = sum + x
i = i +1
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment