[Tutor] Error message...

Victoria Homsy victoriahomsy at yahoo.com
Thu Aug 23 16:17:36 CEST 2012


Dear all, 

Sorry to bother you with a beginner's problem again... 

I have tried to write a program that can check if a string is a palindrome. My code is as follows:


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 try to run it in terminal I get the following error message: 

Traceback (most recent call last):
  File "recursion.py", line 5, in <module>
    isPalindrome('aba')
  File "recursion.py", line 3, in isPalindrome
    else: return s(0) == s(-1) and isPalindrome (s[1:-1])
TypeError: 'str' object is not callable


I don't see why this wouldn't work...

Many thanks in advance. 

Kind regards,

Victoria 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120823/cd144892/attachment.html>


More information about the Tutor mailing list