The next palindrome for given number(s)

 The following program takes user input as number(s) and tells whether the input is a palindrome. If it is not, it will return the next palindrome for that number.


   ncases = int(input("How many cases: "))

for i in range(ncases):
    case = input(f"Enter your case {i+1}: ")
    if case == case[::-1]:
        print("This is a palindrome")
    else:
        pali = case[:]
        while pali != pali[::-1]:
            pali =  int(pali) + 1
            pali = str(pali)
            if pali == pali[::-1]:
                print(f"The next palindrome for case {case} is {pali}")

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes