filmov
tv
Python strong number over a range or checking user input number is strong number or not

Показать описание
A number is called strong number if the number is equal to the sum of factorials of digits of the number.
Number 145 is a strong number as sum of factorial of 1 , 4 and 5 is equal to 145
There are three parts in this script.
1. Function to get Factorial of a number
2. Collecting all digits of the number
3. Finding sum of the factorial of digits and comparing
Factorial of a number n is multiplication of 1 to n, say factorial or 4 is 24.
To find all digits of input number we will keep the input number as string and then find out each char by looping through them.
Once each char is collected we will call the factorial function and pass the each char as number to the function. We will sum of the return values and finally by using if condition check we will see if it is same as input number or not.
If both are equal then the input number is a strong number.
We can change the code by using for loop in place of asking user input and check all the numbers with a range as strong number or not.