forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Solution for Problem 20
- Loading branch information
Thejus-Paul
committed
Nov 27, 2017
1 parent
c787a22
commit 0337441
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters