On 08/23/2012 11:33 AM, Victoria Homsy wrote: > > 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. > >
Could we trouble you for two obvious details? What version of Python are you running? What exactly is your error message? There are at least two possibilities, since two different versions of Python will give two different error messages. Or you could finesse the error by reverting the function to the version that worked, and printing in the calling code. The function shouldn't be printing in any case. While i've got your attention, could I talk you out of posting html messages to a text forum? All the indentation of those code fragments is lost, for me and probably most people. And don't top-post. Put your comments AFTER the part you quote from earlier messages. -- DaveA _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor