Strong & Amstrong Numbers in Python

#---------------------------- Check whether a number is strong number ------------------------

'''A number is said to Strong number if sum of factorial of all of its digit is equal to the original number '''

num = int(input("Enter a number : "))
fact=1
temp =num
sum =0
while(num>0):   
    last= num % 10  # divides the last digit
    num = num //10  # removes last digit
    fact = 1    # reset fact = 1 after completing one last digit 
    for i in range(1,last+1):
        fact =fact*i
    sum += fact
if sum ==temp:
    print(temp,"is a strong number.")
else:
    print(temp,"is not a strong number.")
#---------------------------- Check whether a number is amstrong number ----------------------

'''A number is said to be Amstrong number if sum of all digits to power of number of digits is equal to the original number '''
num = int(input("Enter the number : ")) #  getting input from user
ams = num # assigning input value to the s variable
b = len(str(num))
sum1 = 0
# checking amstrong
while num != 0:
	rem = num % 10
	sum1 = sum1+(rem ** b)
	num = num//10
if ams == sum1:
	print("The given number", ams, "is armstrong number")
else:
	print("The given number", ams, "is not armstrong number")

#---------------------------- Check whether a number is amstrong number ----------------------

'''A number is said to be Amstrong number if 'sum of all digits to power of number of digits ' is equal to the original number '''

num = int(input("Enter a number :"))
sum=0
count =0
temp =num

while(num>0):
    num=num//10
    count +=1
num =temp
while(num>0):
    last = num % 10
    num = num//10
    pow =1
    for i in range(1,count+1):
        pow *= last
    sum += pow
if(sum == temp):
    print(temp,"is a Amstrong number")
else:
    print(temp,"is not a Amstrong number")
print()

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available