This is a Python Program to check if a number is a strong number.
The program takes a number and checks if it is a strong number.
1. Take in an integer and store it in a variable.
2. Using two while loops, find the factorial of each of the digits in the number.
3. Then sum up all the factorials of the digits.
4. Check if the sum of the factorials of the digits is equal to the number.
5. Print the final result.
6. Exit.
Here is source code of the Python Program to check if a number is a strong number. The program output is also shown below.
sum1=0 num=int(input("Enter a number:")) temp=num while(num): i=1 f=1 r=num%10 while(i<=r): f=f*i i=i+1 sum1=sum1+f num=num//10 if(sum1==temp): print("The number is a strong number") else: print("The number is not a strong number")
1. User must enter the number and store it in a variable.
2. A copy of the original number is made as the original value will get altered in the later course of the program.
3. Using a while loop, each of the digits of the numbers is obtained.
4. Then the other while loop is used to find the factorial of the individual digits and store it in a sum variable.
5. If the sum of the factorial of the digits in a number is equal to the original number, the number is a strong number.
6. The final result is printed.
Case 1: Enter a number:145 The number is a strong number. Case 2: Enter a number:234 The number is not a strong number.
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Check Python Books
- Practice Programming MCQs
- Apply for Programming Internship
- Check Information Technology Books
- Apply for Python Internship