Determine whether a number is a perfect number, an armstrong number or a palindrome

number=int(input('enter any 3 digit number'))
sum=0
i=0
upto=int(number/2)+1
for i in range(1,upto):
    if(number%i==0):
      sum=sum+i
if(number==sum):
      print('number is perfect number')

number=str(number)

i=0,sum=0

while(i<3):

     sum=sum+(int(number[i]))**3

if(sum==int(number)):

     print('number is armstrong number')

numberstr=str(number)

digits=len(numberstr)
upto=int(digits/2)+1
success=False
for j in range(0,upto):
  if(numberstr[j]==numberstr[digits-1]):
    digits=digits-1
    success=True
    continue
else:
  print('number is not palindrome')
  success=False
  break
if(success==True):
   print('number is palindrome')

Explanation: Perfect number, is a positive integer that is equal to the sum of its proper divisors possible excluding the number itself. we will check the proper divisor  numbers upto half of the input number, because no integer number more than half of the input number can divide number properly. so we will run for loop upto half of input number. we are checking each number if it can divide the input number properly or not using modulus operator. if it is a divisor then we will add it to total sum. after the loop we are checking if sum is equal to number, if yes then number is perfect number.

Armstrong number: is a n digit number whose sum of n power of each digit is equal to number itself. we have taken example of a 3 digit number here. we have first converted the number to string, because we want to take each digit seperately by using string indexing. initialized sum and i to 0. then program enters the while loop.

in while loop we run loop 3 times for 3 digits. at each index we again converted each character digit to integer using int() function and computed its 3rd power. sum is adding the sum of all digit here. then we checked the sum with number again and printed the message if its true.   

Palindrome number: A palindrome number is a number if it is same either read from left to right or from right to left. for example 787, 234432,484 etc. we have again converted the number to string and taken the length of digits using len() function and we want to run the loop till half of the length of digits, because we will use indexing from last to central index digit also. we will check  digits from both ends of number one by one till we reach same digit index. 

inside the loop we are decreasing digits index from last of number at each iteration. so we are checking digits from both the ends. if digits are same loop will continue and success flag will remain true, other wise program will print number is not palindrome and success flag will become false and loop will break and control comes out of the loop.

finally we are checking success flag if its true , it means full loop was executed and all digits were same. program will print number is palindrome.