forked from seeditsolution/pythonprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome
More file actions
24 lines (18 loc) · 673 Bytes
/
palindrome
File metadata and controls
24 lines (18 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Python3 code to demonstrate
# checking a number is palindrome
# using math.log() + recursion + list comprehension
import math
# the recursive function to reverse
def rev(num):
return int(num != 0) and ((num % 10) * \
(10**int(math.log(num, 10))) + \
rev(num // 10))
# initializing number
test_number = 9669669
# printing the original number
print ("The original number is : " + str(test_number))
# using math.log() + recursion + list comprehension
# for checking a number is palindrome
res = test_number == rev(test_number)
# printing result
print ("Is the number palindrome ? : " + str(res))