Python program to check whether entered number is palindrom and armstrong by using function.

#Python program to check whether entered number is palindrom and armstrong by using function.


def armstrong():
    N=input("Enter number to check if its armstrong number or not:")
    lenght=len(str(N))
    N=int(N)

    sum=0
    temp=N
    while (temp>0):
        R=temp%10
        sum=sum+R**lenght
        temp=temp//10

    if(N==sum):
        print("\n%d"% N,"is an armstrong number.")
    else:
        print("%d"% N,"is not an armstrong number.")
    return

def palindrome():
    N=int(input("\nEnter a number to check if its palindrome or not:"))
   
    temp=N
    rev=0
    while(temp>0):
        R=temp%10
        rev=rev*10+R
        temp=temp//10
    if(N==rev):
        print("%d"% N," is a palindrome.")
    else:
        print("%d"% N, "is not a palindrome.")

 #This method can also be use for checking if the string or integer is palindrome or not.   
    #string=str(N)
    #rev_str=reversed(string)
    #if(list(rev_str)==list(string)):
    #    print(string+" string is palindrome.")
    #else:
    #    print(string+" this string is not palindrome.")

    return

palindrome()
armstrong()

Comments

Popular posts from this blog

Python program to calculate age and year when user will be 100 years old