is it possible to store a variable from a while loop to a function and then call that same variable from the function at the end of the loop
for eg:during while loop, problem here is that when i try to retrieve the variable from store() it fails…as it needs arguments to be passed..
def store(a,b,c):
x1 = a
y1 = b
z1 = c
return (x1,y1,z1)
def main():
while condition:
x = .......
y = .......
z = .......
......
......
store(x,y,z) #store to function...
......
......
......
s1,s2,s3 = store()
......
......
......
Hmmm, unless I am misunderstanding, this is a classic non-solution to a non-problem.
Why not just use the language as it is?
Depending on the type of
x,yandzyou may have to be careful to store acopyinto the tuple.(Also, your indentation is wrong, and there is no such thing as
endin python.)Update: Ok, if I understand better, the question is just to be able to use the previous value the next time through. In the simplest case, there is no problem at all: the next time through a loop, the the value of
x,y, andzare whatever they were at the end of the previous time through the loop (this is the way all programming languages work).But if you want to be explicit, try something like this:
(but again, note that you don’t need
x_prevat all here:x=something_funky(x)will work.)