mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-22 05:16:39 +08:00
increment 1
This commit is contained in:
27
project_euler/Problem 20/sol1.py
Normal file
27
project_euler/Problem 20/sol1.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Finding the factorial.
|
||||
def factorial(n):
|
||||
fact = 1
|
||||
for i in range(1,n+1):
|
||||
fact *= i
|
||||
return fact
|
||||
|
||||
# Spliting the digits and adding it.
|
||||
def split_and_add(number):
|
||||
sum_of_digits = 0
|
||||
while(number>0):
|
||||
last_digit = number % 10
|
||||
sum_of_digits += last_digit
|
||||
number = int(number/10) # Removing the last_digit from the given number.
|
||||
return sum_of_digits
|
||||
|
||||
# Taking the user input.
|
||||
number = int(raw_input("Enter the Number: "))
|
||||
|
||||
# Assigning the factorial from the factorial function.
|
||||
factorial = factorial(number)
|
||||
|
||||
# Spliting and adding the factorial into answer.
|
||||
answer = split_and_add(factorial)
|
||||
|
||||
# Printing the answer.
|
||||
print(answer)
|
5
project_euler/Problem 20/sol2.py
Normal file
5
project_euler/Problem 20/sol2.py
Normal file
@ -0,0 +1,5 @@
|
||||
from math import factorial
|
||||
def main():
|
||||
print(sum([int(x) for x in str(factorial(100))]))
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user