For a start, instead of declaring an emptyStr → you can just write ''.join(stuff) plus you should never reference anything from outside the function other than constants.
Then for some order - usually you would put the setup first, meaning the definition of the function.
Within your function you reference userInput which is from outside, instead of word which you should use.
As for the check - what are you doing there? First you reverse the word, turn it into a list and turn the list back into a string… And then you reverse it again? aren’t you reversing the string twice?
strForPalindrome = emptyStr.join(reversed(word))
“”“Adding reversed string to list is unnecessary. Just use the emptyStr.join(reversed(word))”“”
if word == strForPalindrome:
print(“it’s a palindrome”)
print(“it’s not a palindrome”)
The code worked perfectly as I had envisioned. But one thing I don’t get is that strForPalindrome is the reverse of the original word so putting them in the if block shouldn’t be equal. As the reversed word is the reverse of the original word.
In the if statement, you are checking if the original word and the reversed word (strForPalindrome) are equal. If they are equal, that means it is a palindrome. If you reverse the string , compare with the original word and they are not equal, then you know it is not a palindrome.