Answer to Question #217495 in Python for sai

Question #217495

Largest Palindrome

You are given an integer

N. Find the largest palindrome which is less than N.Input

The input contains a single integer

N.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.


1
Expert's answer
2021-07-15T02:45:46-0400
N = int(input())


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