Skip to content

Instantly share code, notes, and snippets.

@Logic2apply
Created November 18, 2021 11:16
Show Gist options
  • Save Logic2apply/6c78a553270bd09e9c0a626c81bd556d to your computer and use it in GitHub Desktop.
Save Logic2apply/6c78a553270bd09e9c0a626c81bd556d to your computer and use it in GitHub Desktop.
Palindromify List. You are given a list that contains some numbers. You have to print a list of the next palindromes only if the number is greater than 10; otherwise, you will print that number.

Palindromify List

Problem Statement:-

You are given a list that contains some numbers. You have to print a list of the next palindromes only if the number is greater than 10; otherwise, you will print that number.

Input:

Enter the length of the list: 10

  1. Enter Number: 584585456
  2. Enter Number: 65543659
  3. Enter Number: 564321285
  4. Enter Number: 54512
  5. Enter Number: 5452548
  6. Enter Number: 972318
  7. Enter Number: 64197
  8. Enter Number: 54132

Output:

Input List:

[584585456, 65543659, 564321285, 56432, 5142, 54512, 5452548, 972318, 64197, 54132]

Output List:

[584585485, 65544556, 564323465, 56465, 5225, 54545, 5453545, 973379, 64246, 54145]

def nextPalindrom(n):
next = n
while not is_Palindrom(next):
next += 1
return next
def is_Palindrom(n):
return str(n) == str(n)[::-1]
if __name__ == "__main__":
listSize = int(input("\nEnter the length of the list: "))
numList = []
for i in range(listSize):
num = int(input(f"{i+1}. Enter Number: "))
numList.append(num)
print(f"\nInput List:\n{numList}\n\nOutput List:\n{[nextPalindrom(i) for i in numList]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment