[Edu-sig] understanding recursion. . .

Andy Judkis ajudkis at verizon.net
Thu Feb 8 06:05:59 CET 2007


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



More information about the Edu-sig mailing list