[Tutor] Error message...
Victoria Homsy
victoriahomsy at yahoo.com
Thu Aug 23 16:42:57 CEST 2012
Excellent - thank you so much everyone. All is clear now!!
________________________________
From: Mark Lawrence <breamoreboy at yahoo.co.uk>
To: tutor at 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Cheers.
Mark Lawrence.
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120823/1dfaa210/attachment.html>
More information about the Tutor
mailing list