Determine whether a number is a perfect number an armstrong number or a palindrome Python Program
# Palindrome (12321 is Palindrome)
number=int(input("Enter any number:"))
num=number
num1= number
rev=0
while num>0:
digit=num%10
rev=rev*10+digit
num=int(num/10)
if number==rev:
print(number ,'is a Palindrome')
else:
print(number , 'Not a Palindrome')
# Armstrong number is equal to sum of cubes of each digit
sum = 0
temp = num1
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num1 == sum:
print(num1," is an Armstrong number")
else:
print(num1," is not an Armstrong number")
# Perfect number, a positive integer that is equal to the sum of its proper divisors.
sum1 = 0
for i in range(1, number):
if(number % i == 0):
sum1 = sum1 + i
if (sum1 == number):
print(number, " The number is a Perfect number")
else:
print(number, " The number is not a Perfect number")
# Palindrome (12321 is Palindrome)
number=int(input("Enter any number:"))
num=number
num1= number
rev=0
while num>0:
digit=num%10
rev=rev*10+digit
num=int(num/10)
if number==rev:
print(number ,'is a Palindrome')
else:
print(number , 'Not a Palindrome')
# Armstrong number is equal to sum of cubes of each digit
sum = 0
temp = num1
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num1 == sum:
print(num1," is an Armstrong number")
else:
print(num1," is not an Armstrong number")
# Perfect number, a positive integer that is equal to the sum of its proper divisors.
sum1 = 0
for i in range(1, number):
if(number % i == 0):
sum1 = sum1 + i
if (sum1 == number):
print(number, " The number is a Perfect number")
else:
print(number, " The number is not a Perfect number")
# Palindrome (12321 is Palindrome) number=int(input("Enter any number:")) num=number num1= number rev=0 while num>0: digit=num%10 rev=rev*10+digit num=int(num/10) if number==rev: print(number ,'is a Palindrome') else: print(number , 'Not a Palindrome') # Armstrong number is equal to sum of cubes of each digit sum = 0 temp = num1 while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 if num1 == sum: print(num1," is an Armstrong number") else: print(num1," is not an Armstrong number") # Perfect number, a positive integer that is equal to the sum of its proper divisors. sum1 = 0 for i in range(1, number): if(number % i == 0): sum1 = sum1 + i if (sum1 == number): print(number, " The number is a Perfect number") else: print(number, " The number is not a Perfect number")
Output:
Enter any number:12321 (12321, 'is a Palindrome') (12321, ' is not an Armstrong number') (12321, ' The number is not a Perfect number')
Enter any number:2356 (2356, 'Not a Palindrome') (2356, ' is not an Armstrong number') (2356, ' The number is not a Perfect number') >>>
Enter any number:153 (153, 'Not a Palindrome') (153, ' is an Armstrong number') (153, ' The number is not a Perfect number') >>>
Enter any number:6 (6, 'is a Palindrome') (6, ' is not an Armstrong number') (6, ' The number is a Perfect number') >>>