This Python program finds the largest palindrome number less than the given number num. It defines a function Previous_Palindrome that takes num as input.
The function uses a for loop to iterate over all numbers less than num in reverse order (i.e., from num-1 down to 1). For each number x, it checks whether x is equal to its reverse string representation str(x)[::-1]. If x is a palindrome, the function returns x.
The main program takes an input num from the user and calls the function Previous_Palindrome with num as argument. The result is then printed to the console.
def Previous_Palindrome(num): for x in range(num-1,0,-1): if str(x) == str(x)[::-1]: return x num = int(input("Enter the Number :")) print(Previous_Palindrome(num))
Enter the Number :2374 2332
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions