Home > Problem, Projects/Experiments, Python > Python: Factorial Digit Sum

Python: Factorial Digit Sum

Python: Factorial Digit Sum
Problem 20 @ projectEuler

The Task: The task in projectEuler P20 is to get the sum of the digits in the number Factorial of 100!

Factorial NdefinitionThe factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 10! = 10 × 9 × … × 3 × 2 × 1 = 3628800.

Problem 20 is another easy problem in projectEuler, and we will write two functions to solve it. First one is a Factorial_digit_sum this one will return the factorial of a number. The second function will calculate the sum of all digits in a number N and we will call it sum_of_digits.

Clarification As long as i just start solving or posting my answers to projectEuler portal, i am selecting problems and not going through them in sequence, that’s way my posts are jumps between problems, so if i am posting the code to solve problem 144 (for example) that does’t meaning that i solve all problems before it.

print of solved screen:

The Code:

#Python: Factorial Digit Sum
#Problem No.20 on projectEuler

def Factorial_digit_sum(num):

if (num == 1) :

return 1


return num * Factorial_digit_sum(num-1)

fact =Factorial_digit_sum(100)
print fact,’is the Factorial of {}.’.format(num)

def sum_of_digits(dig):

t = 0

for each in dig:

t = t + int(each)

print ‘\nThe sum of your number is’,t


Follow me on Twitter..

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s