Excellent - thank you so much everyone. All is clear now!! 

________________________________
 From: Mark Lawrence <breamore...@yahoo.co.uk>
To: tutor@python.org 
Sent: Thursday, 23 August 2012, 15:29
Subject: Re: [Tutor] Error message...
 
On 23/08/2012 15:17, Victoria Homsy wrote:
> Dear all,
>
> Sorry to bother you with a beginner's problem again...

You're welcome as that's what we're here for.

>
> 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...

Always easier for another pair of eyes.  The TypeError tells you exactly 
what the problem is.  Just look very carefully at the return after the 
else and compare your use of the function parameter s.  Then kick 
yourself and have another go :)

>
> Many thanks in advance.
>
> Kind regards,
>
> Victoria
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Cheers.

Mark Lawrence.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to