1
Within a function I have a cumulative variable, and I call this function over and over again, the problem that it loses values every time it enters. Summing up what I want to do is:
def teste(a):
a=a+1
c=7
print a
return c
def main():
a=1
for b in range(0,5):
c=teste(a)
main()
the exit is:
would like to maintain the value of a, and the output in that case be increased.
You are with two
a
s in your code: one is the formal parameter of the function and the other is the global variable.– Pablo Almeida
this is a simple code to reproduce the idea, in case if it were global it would work, think that the second part is within a function
– Joannis