# Determine whether a number is a perfect ,an Armstrong or a palindrome number

## What is perfect number?

According to Wikipedia, In number theory, a perfect number is a positive integer  that is equal to the sum of its positive divisor, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number.

In other definition, a perfect number is a number that is half the sum of all of its positive divisors including itself; For instance 28 is perfect number as 1+2+4+7+14+28 = 56 . Here, 28 has divisors 1,2,4,7,14,28(including itself), and 56 = 2 * 28 . that’s why 28 is perfect number.

Examples of perfect numbers are 6,28,496,8128 and many more.

## Python program to determine whether number is perfect number or not

This Python program for Perfect Number allows the user to enter any number. Using this number it will calculate whether the number is Perfect number or not using the Python if-else Loop.

### Program Logic:

• Take a any number from user using input method
• Use for loop to iterate through number
• Use if statement within for loop to add the proper divisors of the integer to the sum variable.
• Compare the original value with Sum value.
• If they exactly matched, then it is an perfect number else it is not perfect.

### Program code:

```n = int(input("Enter any number to check whether it is perfect number or not  : "))
sum = 0
# Check for perfect number
for i in range(1,n):
if n%i==0:
sum = sum + i

if sum == n :
print( n,"is perfect number")
else :
print( n, "is not perfect number")

```

## What is an Armstrong number?

According to Wikipedia, in a number theory, If the given number is equal to the sum of the cube of each digit present in that integer, then that number can be an Armstrong Number in Python.

For example, 153 is Armstrong Number; 153 number is 3 digit number

so sum of cube of each digit = original number

= 1+53 +33

= 1 + 125 + 27

= 153 Hence; 153 = 153

For Example, 152 is not Armstrong number; 152 is 3 digit number

= 1+53 +23

= 1 + 125 + 8

= 134 ; Hence 134 is not equal to 152

so sum of cube of each digit is not equal to original number. that’s why 152 is not Armstrong number

## Python program to check whether given number is an Armstrong number or not

### Problem Statement:

This Python program allows the user to enter any positive integer. And then, checks whether a number is Armstrong Number or Not using the While Loop

### Program Logic:

• Take any number from user using input method.
• Count the Number of individual digits (For Example, 153 means 3 digit).
• Divide the given number into individual digits (For Example, Divide 153 into 1, 5, and 3 ).
• Calculate the power of n for each individual and add those numbers.
• Compare the original value with Sum value.
• If they exactly matched, then it is an Armstrong number else it is not Armstrong.

```#check for armstrong number
n = int(input("Enter any number to check whether it is  an armstrong   : "))
temp = n
total = 0
while temp > 0 :
digit = temp %10
total = total + (digit**3)
temp = temp//10
if n == total:
print( n,"is an armstrong number")
else :
print( n, "is not armstrong number")

```

## What is Palindrome number?

In number theory,If the given number is equal to reverse of digit of number,then that number can be Palindrome number in python. In other word, Palindrome number is number that remain same when its digit are reversed.

For Example, 141 is Palindrome number; 141 is 3 digit number.

reverse of digit of number = original number

When we reverse its digit ,we get same number that’s why 141 is palindrome number.

For Example,142 is not Palindrome number; When we reverse its digit, we get 241 which is not equal to 142 that’s why 142 is not palindrome number.

Example of Palindrome numbers : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, …

## Python program to check whether given number is palindrome number or not

This Python program allows the user to enter any positive integer. And then, checks whether a number is Palindrome Number or Not using the While Loop

### Program Logic:

• Take any number from user using input method
• Store number in temporary variable say temp.
• Count the Number of individual digits (For Example, 121 means 3 digit).
• Divide the given number into individual digits (For Example, Divide 121 into 1, 2, and 1).
• Calculate the reverse of number by adding remainder
• Compare the original number with reverse number
• If they exactly matched, then it is Palindrome number else it is not Palindrome.

### Program Code:

```#check for palindrome number
n = int(input("Enter any number to check whether it is palindrome  : "))
temp = n
rev = 0
while n > 0:
d = n % 10
rev = rev *10 + d
n = n//10
if temp == rev :
print( temp,"is palindrome number")
else :
print( temp, "is not palindrome number")

```

## Lets combine above 3 source code to determine given number is perfect,an armstrong or palindrome number.

### Write a python program to determine given number is perfect,an armstrong or palindrome number using if-else,for and while loop

```n = int(input("Enter any number to check whether it is perfect ,armstrong or palindrome  : "))
sum = 0
# Check for perfect number
for i in range(1,n):
if n%i==0:
sum = sum + i

if sum == n :
print( n,"is perfect number")
else :
print( n, "is not perfect number")
#check for armstrong number
temp = n
total = 0
while temp > 0 :
digit = temp %10
total = total + (digit**3)
temp = temp//10
if n == total:
print( n,"is an armstrong number")
else :
print( n, "is not armstrong number")
#check for palindrome number
temp = n
rev = 0
while n > 0:
d = n % 10
rev = rev *10 + d
n = n//10
if temp == rev :
print( temp,"is palindrome number")
else :
print( temp, "is not palindrome number")

```

<
{"ft_lang_label":"__label__en","ft_lang_prob":0.732778,"math_prob":0.9987279,"size":5806,"snap":"2023-14-2023-23","text_gpt3_token_len":1547,"char_repetition_ratio":0.19234747,"word_repetition_ratio":0.3859489,"special_character_ratio":0.29865655,"punctuation_ratio":0.13587406,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9994466,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-06T14:20:22Z\",\"WARC-Record-ID\":\"<urn:uuid:fcbc4c61-fad5-4d27-957c-bdf8be8a4847>\",\"Content-Length\":\"110758\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6f78eb6d-59a2-4a0e-8395-c3abacc44700>\",\"WARC-Concurrent-To\":\"<urn:uuid:229d11ad-60a9-415f-8a47-9a853bf35f6b>\",\"WARC-IP-Address\":\"217.21.84.81\",\"WARC-Target-URI\":\"https://technocrash.online/archives/1331\",\"WARC-Payload-Digest\":\"sha1:7TSLF75BGHVGRYLEGVJMN6BQONZOM6DX\",\"WARC-Block-Digest\":\"sha1:C4EYXSQNRTVGYX2SD7LQ35E6RCHQBDXJ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224652569.73_warc_CC-MAIN-20230606114156-20230606144156-00336.warc.gz\"}"}