A palindrome is a line that reads the same back and forth. Examples of palindromes include lol, abba, radar, and pickle elkcip. Indicates whether it works under all circumstances described in the following documentation: '' 'Return True if string s is a palindrome and returns False otherwise.' ''
def palindrome2(s):
n = len(s)
pal = True
for i in range(n/2):
if s[i] == s[n-i-1]:
pal = True
else:
pal = False
return pal
I do not understand why this function does not work. It seems to me that the function works. Booleans seem to be used incorrectly, but I don't understand how the booleans above are not used properly. Can someone please explain this to me?
source
share