Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def factorial(n):
- if n < 0 or n != int(n):
- print("Error using factorial function")
- return -1000
- elif n == 0:
- return 1
- else:
- fact = list()
- fact.append(1)
- for i in range(1, n+2):
- fact.append(i * fact[i-1])
- return fact[n]
- def countDigits(n):
- string = str(n)
- sum = 0
- for i in range(len(string)):
- ch = string[i]
- sum += int(ch)
- return sum
- # MAIN FUNCTION
- n = 100
- fact = factorial(n)
- print(str(n) + "! = " + str(fact))
- print("The sum of all the digits of " + str(n) + "! is: " + str(countDigits(fact)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement