### Python Problem 4: Solution | Python Tutorials For Absolute Beginners In Hindi #110

This is the solution to Python Problem #4. Hope you enjoyed doing it. The problem statement is also given below for your convenience.

#### Problem Statement:-

A palindrome is a string that, when reversed, is equal to itself. Example of the palindrome includes:

676, 616, mom, 100001.

You have to take a number as an input from the user. You have to find the next palindrome corresponding to that number. Your first input should be the number of test cases and then take all the cases as input from the user.

3

451

10

2133

#### Output:

Next palindrome for 451 is 454

Next palindrome for 10 is 11

Next palindrome for 2311 is 2222

#### Code as described/written in the video

``````'''
Author: Harry
Date: 15 April 2019
Purpose: Practice Problem For CodeWithHarry Channel
'''

def next_palindrome(n):
n = n+1
while not is_palindrome(n):
n += 1
return n

def is_palindrome(n):
return str(n) == str(n)[::-1]

if __name__ == "__main__":
n = int(input("Enter the number of test cases\n"))
numbers = []
for i in range(n):
number = int(input("Enter the number:\n"))
numbers.append(number)

for i in range(n):
print(
f"Next palindrome for {numbers[i]} is {next_palindrome(numbers[i])}")

``````