0

I am a beginner learning python. Right now I am trying to create a code that tells me if a string that was entered by the user is the same backwards. Ex. Hannah, Ana , stats. You get the idea.

This is my code so far. I am trying to figure out why I am not able to check further than the first and last index of the string also would like to get some advice in how to continue because i am stuck. Thank you.

Word = input(“ Enter a word “)

X = 0

Y = len(word)-1

a = word[X]

b = word[Y]


If a == b:

       X += 1

       Y = Y-1

       Print(“is palindrome”)

Else:

       Print(“is not palindrome”) 
Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • 1
    You can check if it is equal to its reverse like `Word == Word[::-1]` – aminrd Jan 18 '20 at 02:18
  • huh I don’t need any values at all just an if and that condition. Thank you. – Alejandro Naranjo Ardila Jan 18 '20 at 02:27
  • Using just an `if` condition is not enough, you need to loop through each character of the string: first and last, first+1 and last-1, first+2 and last-2, and so on. The duplicate already has some answers that does just that. – Gino Mempin Jan 18 '20 at 05:20

0 Answers0