[Tutor] recursion surprise
Steven D'Aprano
steve at pearwood.info
Sun Jun 9 03:45:32 CEST 2013
On 09/06/13 11:18, Jim Mooney wrote:
> On 8 June 2013 18:08, Steven D'Aprano <steve at pearwood.info> wrote:
>
>> Is this enough information for you to fix it?
>
> Yes, I was tripping over myself. Once I simplified it, it became clear:
>
> def addone(n):
> if n > 5:
> return n
> return addone(n + 1)
>
> result: 6
By George, I think you've got it!
:-)
Recursion is one of the more difficult computer science concepts for people to grasp. I don't remember the reference, but I think I read somewhere that something like 50% of professional programmers never understand recursion. Admittedly, most of them are VB or PHP code monkeys, where the standards for "professionalism" can be quite low, but still.
--
Steven
More information about the Tutor
mailing list