The code which you wrote
def checkPalindrome(num):
rev = 0
while num != 0:
d = num % 10
rev = (rev * 10) + d
num = num // 10
print(rev)
if num==rev:
return True
else:
return False
In this line num = num // 10
num
is replaced by num/10
and in next if
condition you are checking num==rev
which is always false. So how many times you give a value it always gives you false.
So if you store num
in a temporary variable
i.e, tempVariable=num
so that you when you reverse the num
you can check the original value with tempVariable
and then do num = num // 10
and in next if
condition you can check tempVariable==rev
which will give you correct result.
Following code will give you correct result for numbers
def checkPalindrome(num):
tempVariable = num
rev = 0
while num != 0:
d = num % 10
rev = (rev * 10) + d
num = num // 10
if tempVariable == rev:
return True
else:
return False
num = int(input())
isPalindrome = checkPalindrome(num)
if (isPalindrome):
print('true')
else:
print('false')