[Tutor] Recursive user input collection problem

Dave Angel davea at ieee.org
Thu Oct 15 13:54:23 CEST 2009


William Witteman wrote:
> Thanks to all who responded.  There were several good points about the
> code itself, all of which both helped and work.
>
> I will likely use Alan's example because I find it the most lucid, but
> the other suggestions are good signposts to other ways to do the same
> thing (but right, as opposed to how I was doing it).
>
> Lie's suggestion that I didn't understand the calling structure of
> Python was right on the money, and his included link helps with that,
> too.  Thanks again.
>   
The problem with that approach is that you're still making unnecessary 
recursive calls.  The problem isn't a recursive one, so why take the 
risks that artificial recursion imposes.

You need a loop, and putting a while True:  around the whole thing 
solves it nicely.  Don't *call* the function again, just loop back and 
do the operation again.  That's what loops are for.

Incidentally, learning about recursion is a very good thing, and 
useful.  I just don't think it's the right answer here.

DaveA


More information about the Tutor mailing list