[email protected] wrote:
> What I wanted to happen is when the user typed something other than 'y' or
> 'yes' after being asked 'go again?', the batman==False line would cause the
> program to stop asking anything and say 'this is the end'. Instead, what is
> happening is that the program just keeps going. I figured that after defining
> the function (thingy(), repeat()), that the while statement would repeat
> until the 'go again' user input was something other than 'y' or 'yes', and
> the batman==False part of the repeat() function would cause the 'while
> batman==True' part to become False and end. You probably answered my question
> and I'm too dumb to see it, but that's a slight elaboration on my problem.
When you assign a variable inside a function, it has no effect on a
global variable with similar name. In order to make it change the
global, you'd have needed the global declaration.
Try this:
var = 42
def myfunc():
var = 90
print "before:", var
myfunc()
print "after:", var
Now, change the function, by adding a declaration:
def myfunc():
global var
var = 90
and the result will change.
--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list