# Why does my function think that “uiouioiu”is a plaindrome? [closed]

I was reading Introduction to Computation and Programming using Python and there in an exercise, we had to write a function which would tell us if a given word is a palindrome or not, recursively.

This is the code which I wrote:

word = input()

def isPalindrome(x):
if len(x) > 1:
if x[0] == x[-1] and isPalindrome(x[1:-1]):
return('The word is Plaindrome.')
else:
return('It is not.')
else:
return(True) #As this is a base case.

print(isPalindrome(word))


This seems to work for all the words I pass into it except uiouioiu. isPalindrome(uiouioiu) returns The word is Palindrome.

Could someone explain what is happening?

EDIT 1: If I modify the code to:

word = input()

def isPalindrome(x):
if len(x) > 1:
if x[0] == x[-1] and isPalindrome(x[1:-1]):
return(True)
else:
return(False)
else:
return(True) #As this is a base case.

print(isPalindrome(word))


isPalindrome(uiouioiu) returns False as expected. Why is this happening?

## closed as off-topic by 200_success, Austin Hastings, vnp, AJNeufeld, esoteApr 25 at 4:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Austin Hastings, vnp, AJNeufeld, esote
If this question can be reworded to fit the rules in the help center, please edit the question.

• Hi. Thanks for the answer. Could you please explain what do you mean by " It is notis converted into True" ? It is not == True evaluates to False! – user199357 Apr 25 at 1:41