Answer to Question #223916 in Python for hari

Question #223916

LARGEST PALINDROME

you are given an integer N . find the largest palindrome which is less than N .


INPUT

the input contains a single integer

OUTPUT

the output should be a single integer which is the largest palindrome that is less than the given input.

EXPLANATION

given N = 45

44 is the largest number which is a palindrome that is less than 45

SAMPLE INPUT 1

45

SAMPLE OUTPUT 1

44

SAMPLE INPUT 2

79

SAMPLE OUTPUT 2

77


1
Expert's answer
2021-08-09T02:29:55-0400
N = int(input('Enter the number : '))


palindrome = -1
# 11 - smallest palindrome
for i in range(11, N):
    if i > palindrome and str(i)[::-1] == str(i):
        palindrome = i
if palindrome == -1:
    print('No palindrome')
else:
    print(palindrome)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS