[Tutor] Error message...

Victoria Homsy victoriahomsy at yahoo.com
Thu Aug 23 17:33:04 CEST 2012





Dear All - sorry to bother you. I just tried to run this program:


def isPalindrome(s):
if len(s) <= 1: return True 
else: return s[0] == s[-1] and isPalindrome (s[1:-1])
isPalindrome('aba')


However when I run it in terminal it doesn't give me any answer - True or False. (I want the program to tell me whether the input string is True or False). In order to get an answer, I assume I would need to tell the program to print something. However I'm not sure where in the program I would do this. I tried this:

def isPalindrome(s):
if len(s) <= 1: return True and print "True"
else: return s[0] == s[-1] and isPalindrome (s[1:-1])
isPalindrome('aba')

However, this does not work - I get another error message. 

Could somebody advise what I'm doing wrong here? Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120823/a07def39/attachment.html>


More information about the Tutor mailing list