I wrote a palindrome iterative method and it returns correct result except for when the string is arena or taxi cat. It returns true for both where it has to return false.
def palIterative(n):
for i in range(0, int(len(n)/2)):
if n[i] != n[len(n) - i - 1]:
return False
break
return True
You don't need break after the return False statement. Return will break out of a function. The problem though is your return True statement has one too many tabs. The return True statement should be after the for loop has completed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With