Palandrome Checking with Python
scottalanmiller last edited by scottalanmiller
I provided one example on how to check a palandrome with Python using recursion. Here is a longer and more traditional example without using recursion. There is some extra print statements to show where the logic is being hit as it runs.
pal = input("Enter the palandrome to verify: ") print("Your palandrome is: ", pal) palLength = len(pal) frontIndex = 0 backIndex = palLength - 1 while True: if frontIndex == backIndex: print("It is an " + pal[frontIndex] + " so far so good.") print("Success.") break if pal[frontIndex] == pal[backIndex]: print("It is an " + pal[frontIndex] + " so far so good.") else: print("Fail.") break if frontIndex == (backIndex - 1): print("It's good.") break else: frontIndex += 1 backIndex -= 1