Python Code for Palindrome Number

 
Determine if the given number is palindrome or not. Print true if it is a palindrome, false otherwise.

Sample Input 1 :
18181
Sample Output 1 :
true
Sample Input 2 :
1832
Sample Output 2 :
false

Solution :

  1. def checkPalindrome(num):
  2. #Implement Your Code Here
  3. temp = num
  4. rev_num = 0
  5. while temp > 0:
  6. a = temp % 10
  7. rev_num = (rev_num * 10) + a
  8. temp = temp // 10
  9. if rev_num == num:
  10. return True
  11. pass
  12. num = int(input())
  13. isPalindrome = checkPalindrome(num)
  14. if(isPalindrome):
  15. print('true')
  16. else:
  17. print('false')

Try it >>
Previous Post Next Post