Created
July 13, 2019 19:48
-
-
Save jatinsharrma/50d942461d5d19cdbd3eb7b771b78ca3 to your computer and use it in GitHub Desktop.
Strong Number (eg 145 = 1! + 4! + 5!)
This file contains hidden or 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
#Write a Python function to find all the Strong numbers in a given list of numbers. | |
def factorial(number): | |
if number == 1: | |
return (number) | |
elif number == 0: | |
return 1 | |
else: | |
return (number * factorial(number-1)) | |
def find_strong_numbers(num_list): | |
result = [] | |
for num in num_list: | |
temp = str(num) | |
answer = 0 | |
for t in temp: | |
answer = answer + factorial(int(t)) | |
if num == answer: | |
result.append(num) | |
return (result) | |
num_list=[145,375,100,2,10] | |
strong_num_list=find_strong_numbers(num_list) | |
print(strong_num_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment