# Program to check a number is palindrome or not without help of a string in Python

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Suppose we have a non-negative integer called num, we have to check whether it is a palindrome or not. We have to solve it without using strings

So, if the input is like num = 25352, then the output will be True

To solve this, we will follow these steps −

• a := 0

• c := num

• while num > 0, do

• r := num mod 10

• num := floor of num / 10

• a :=(10 * a) + r

• if a is same as c, then

• return True

• otherwise return False

## Example

Let us see the following implementation to get better understanding

def solve(num):
a = 0
c = num
while num > 0:
r = num % 10
num = num // 10
a = (10 * a) + r
if a == c:
return True
else:
return False

num = 25352
print(solve(num))

## Input

25352


## Output

True