[Tutor] Recursive user input collection problem

Lie Ryan lie.1296 at gmail.com
Wed Oct 14 11:11:59 CEST 2009

William Witteman wrote:
> I need to collect a couple of integers from a user, but I want to make
> sure that I actually get integers.  I tried this, but subsequent calls
> to the function don't update variable.  I'm not sure this is terribly
> clear - here's the code:
> def getinput(variable,prompt):
>   """
>   Get the input by prompting the user and collecting the response - if it is 
>   a non-integer, try again.
>   """
>   variable = 0

the source of your confusion is misunderstanding of python's calling
model. Here is an article: http://effbot.org/zone/call-by-object.htm

More information about the Tutor mailing list