x=int(input("Enter a number to check whether it is a palindrome number or not here : "))
 m=x
 k=0
 for j in range (m):
      digit=m%10
      k=k*10+digit
      m=m//10
 if k==x:
      print("%d is a palindrome nukber"%(x))
 else:
      print("%d is not a palindrome number"%(x))
 print()

Recommended Answers

All 3 Replies

I would create a function IsPalindrome that checks any string, then pass it a number converted to a string. Why bother with numbers at all? Actually, I did this and the function was four lines including the header.

A palindrome check should be a loop through the first half of the string or 1/2 less checking the mirror byte for a match. To make it a number check, filter for numbers along the way or format number types to a string. For instance, for 9 places check 1 with 9, 2 with 8, 3 with 7, 4 with 6 and who cares about 5! For 1 through length>>1 char n == char length -n +1, with the usual care about the cardinal ordinal numbering of char in a string or array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.