 # Add digits of factorial product and print the sum of all digits in Python , Where did I go wrong?

The purpose of the code is to add the digits of the factorial product such as 5! = 120 and the output is 1 + 2 = 3.

``````import math
num = 10
fac = math.factorial(num)
list = []
n = 0
sum = 0
while fac > 0:
digit = (fac // 10 ** (n-1)) % 10
n += 1
list.append(digit)
for i in list:
sum+=i
break
print(sum)

``````

Are you talking about the checksum?

If so, think again about the single steps:

1. you start by extracting the single digits (as you already did)
2. you decrease the fac value you have by the digit you have already extracted
3. you sum up your extracted digits in a separate variable (as you did but you could also do it without a list)
1 Like

Yes like if we have 6! = 720 , sum = 7 + 2 + 0 = 9

Sorry. I missed to read the forum policy. So I had to edit my answer in the meantime. Hope it helps you.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.