Strong Number

A number is called strong number if the number is equal to the sum of factorials of digits of the number.

Example :
Number 145 is a strong number as sum of factorial of 1 , 4 and 5 is equal to 145
145= 1! + 4! + 5!

Factorial of a number

We will use one function to get the factorial of any input number.
def my_factorial(n):
  b=1
  for i in range(1,n+1):
    b=b*i
  return b

Digits of an input number

We can get length of a string by using len()
a=input("Enter a number")
for i in range(0,len(a)):
  print(a[i])

Full code to check input number is strong number or not is here.

def my_factorial(n):
  b=1
  for i in range(1,n+1):
    b=b*i
  return b
  
a=input("Ener a number : ")
sum=0
for i in range(0,len(a)):
  sum=sum+my_factorial(int(a[i]))
print("Sum of factorial of digits : ",sum)
if int(a)==sum:
  print('This is a strong number : ', a)
else:
  print('This is not a strong number', a)
All Sample codes Armstrong Number


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer