Andy, In the situation that you list, recursion is a natural approach. It has a natural end. there are alternatives, that you may or may not want to take time to mention.
I have a problem with introductory students doing a major project before recursion is introduced, and naively having a nasty web of recursive calls in playing a much more complicated game, and then they have no possible way to end the program or see what happened when they made an error. I would not discourage the student in your context. A side comment about "a lot more going on than meets the eye" or "make sure it ends cleanly" or "worth further study to really understand" would not hurt either. Andy Harrington Andy Judkis 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@python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- Andrew N. Harrington Computer Science Department Director of Academic Programs Loyola University Chicago http://www.cs.luc.edu/~anh 512B Lewis Towers (office) Office Phone: 312-915-7982 Snail mail to Lewis Towers 416 Dept. Fax: 312-915-7998 820 North Michigan Avenue [EMAIL PROTECTED] Chicago, Illinois 60611 _______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig