P.S: I'm new to python (and programming in general), however, I've got this question with regards to checking if a word is a palindrome. Here's my code:
def checkPal(word):
newWord = ""
for j in range(len(word)-1, 0):
newWord = newWord + word[j]
print(newWord) #this doesn't print anything
if(newWord==word):
print("Palandrome!!")
else:
print("sorry")
So this doesn't throw any errors, however, it doesn't work too! I am aware there are other ways of doing it, like:
str(n) == str(n)[::-1]
This works like a charm. But I'd just like to know what's wrong with my code. I can't seem to find a solution. I've tried item assignments separately too:
Word = ""
toAdd = "LetsTryThis"
Word = Word + toAdd[0]
print(Word)
The output:
L
The output is as expected, but this doesn't seem to work in the for loop of my checkPal function. See comment.
Thanks for the help!