# [Edu-sig] understanding recursion. . .

Lloyd Hugh Allen chandrakirti at gmail.com
Thu Feb 8 12:15:29 CET 2007

```iirc, the classic would be to compute fibonaccis recursively and watch
the system grind to a halt in only a handful of iterations. When
googling for "recursive fibonacci", I thought that the last example on
the first page http://blogs.msdn.com/ericlippert/archive/2004/05/19/135392.aspx
would tell me why I'm a moron, but in fact this page also cites fib as
a good way to show recursion gone wrong. Just that we shouldn't....

The comments have decent commentary as well.

On 2/8/07, Andy Judkis <ajudkis at verizon.net> wrote:
> I teach a "serious computer literacy" course to 10th graders.  The course
> covers some things about how hardware works, how the internet works, what
> operating systems do, etc.  The last part is a 3-4 week intro to Python
> programming.  I've encountered some interesting student behavior and I'm
> curious to know how those of you who are better and more experienced
> teachers would suggest handling it.
>
> Specifically, I've found that many kids seem to have a natural ability to
> use
> recursion, but they don't realize that they're doing it, and they don't
> understand the implications.  Case in point:  I give them a trivial "guess
> the random number" game and they add trivial features to it that require
> some basic programming concepts.  One of the features is to have the program
> ask the user if he/she wants to play again.  My expectation was that they'd
> write a loop like this:
>
> while True:
>     play_game()
>     resp = raw_input("Play again?")
>     if resp == "no":
>         break
>
> Instead, what many of them do is to put the logic inside the play_game()
> routine:
>
> def play_game():
>     . . .
>     . . .
>     resp = raw_input("Play again?")
>     if resp == "yes":
>         play_game()
>
> As far as they can tell, this works fine.  When I look back on my own
> experiences, it took me a long time to think recursively, and it would never
> have occurred to me to code it the way they do.  I envy them their natural
> (if imperfect) grasp of the approach.  But they don't have any clue that
> there's
> a call stack involved, or that someday this could get them in trouble.  I
> shudder
> to think about the blank looks that I will get if I try to explain why it
> could be a problem.  So far, I've handled it by pointing out "that's
> recursion,
> you can do that but there's a little more to it and if you're interested,
> ask me or look into it further on your own."  I guess that lets me off the
> hook
> but it doesn't feel quite right.  Other options I can think of are:
> 1) try to explain it and lose most of the class
> 2) just say "I don't allow it, I have a good reason, let me know if you want
> an
> explanation"
> Neither of these feels quite right, either.  These are bright kids but they
> have
> great difficulty understanding things like function parameters and return
> values,
> and I really think recursion is beyond them at this point.
>
> Anybody have any suggestions or similar experiences?
>
> Thanks,
> Andy Judkis
> Academy of Allied Health and Science
> Neptune, NJ
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
```