I've been fighting with this for three hours now.
ETA- Should have mentioned this, but for purposes of this class, not allowed to use global variables.
Within function main(), I want to run a function firstPass if and only if it's the first time the whole function is being run. The firstPass function initializes a couple variables and prints some information that is not interesting if it's not the first time you see it.
I duly have:
#Initialize variables that need to run before we can do any work here
count = 0
def firstPass():
x = 5
y = 2
print "Some stuff"
count = count + 1
print "Count in firstPass is",count
return count,x,y
def main ():
print "Count in main is",count
if count == 0:
firstPass()
else:
#Do a whole bunch of other stuff that is NOT supposed to happen on run #1
#because the other stuff uses user-modified x and y values, and resetting
#to start value would just be self-defeating.
main()
This returns correctly on the first pass, but on subsequent passes, returns:
Count in main is 1
This is also a problem for my user-modified x and y values within other functions. Though I haven't modified them here, I did include them because I need to pass multiple values between functions later on in the code, but who wants to read all that when I could just put them here for the sake of the example...
I was under the impression that
return [variable]
passed the CURRENT (i.e. whatever that variable became within the current function) value of the variable back to other subsequent functions. Either my understanding is wrong, or I am just doing it wrong.