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?
The logic behind reversing the reversed string is that we get the original word. Hence I said if original word is equal to reversed reversed string then return āitās a palindromeā
def checkIfPalindrome(word):
strForPalindrome = emptyStr.join(reversed(word))
print(strForPalindrome)
āāāAdding reversed string to list is unnecessary. Just use the emptyStr.join(reversed(word))āāā
if word == strForPalindrome:
print(āitās a palindromeā)
else:
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.