0% found this document useful (0 votes)
0 views2 pages

Practical 10

The document describes how to determine if a number is a perfect number, an Armstrong number, or a palindrome. A perfect number is equal to the sum of its proper divisors, while an Armstrong number equals the sum of the cubes of its digits. A palindrome remains the same when its digits are reversed.

Uploaded by

Tiyasa Mahapatra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Practical 10

The document describes how to determine if a number is a perfect number, an Armstrong number, or a palindrome. A perfect number is equal to the sum of its proper divisors, while an Armstrong number equals the sum of the cubes of its digits. A palindrome remains the same when its digits are reversed.

Uploaded by

Tiyasa Mahapatra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

WAP to determine whether a given number is a perfect number, an armstrong

number or a palindrome.
Perfect Number : A perfect number is a positive integer that is equal to the sum of
its proper positive divisors, that is, the sum of its positive divisors excluding the
number itself (also known as its aliquot sum). Equivalently, a perfect number is a
number that is half the sum of all of its positive divisors (including itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive
divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all
its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. The next perfect number is 28 = 1 + 2
+ 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.
An Armstrong number is the sum of cubes of each digit is equal to the number
itself.
For example:
153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.

num = int(input("Enter a number: "))


order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")

A palindromic number (Palindrome) is a number (such as 16461) that remains the


same when its digits are reversed

You might also like