ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Palandrome Checking with Python

    Developer Discussion
    python
    1
    1
    866
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      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
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post