Possible duplicate:
Maximum recursion depth?
I have another problem with my code. I take my first program in Vpython, and I need to do a simulation of mixing two gases. At first I had a problem with the boundaries, but now that the balls (representing gas particles) remain within the boundaries, there are different errors. After a few seconds, I get an error message, which is shown below the source code of my function. The code:
def MovingTheBall(listOfBalls,position,numCell,flagOfExecution): flag = 0 if flagOfExecution==0: positionTmp = position else: positionTmp = (position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0) for i in range( 0, len(listOfBalls) ): if positionTmp==listOfBalls[i].pos: flag=1 if flag==1: return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) else: if positionTmp[0]==0 or positionTmp[0]>=numCell or positionTmp[0]<=-numCell or positionTmp[1]>=numCell or positionTmp[1]<=-numCell: return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) return positionTmp
error:
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) File "gaz.txt", line 138, in MovingTheBall return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) File "gaz.txt", line 138, in MovingTheBall return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) File "gaz.txt", line 138, in MovingTheBall return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) File "gaz.txt", line 138, in MovingTheBall return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) File "gaz.txt", line 138, in MovingTheBall return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1) File "gaz.txt", line 130, in MovingTheBall if positionTmp==listOfBalls[i].pos: RuntimeError: maximum recursion depth exceeded while calling a Python object
Can anyone think of a way to simplify my function?
I run the it while loop function:
while 1: rate(20) for i in range(0,len(self.listOfBalls)): self.listOfBalls[i].pos=poruszanie(self.listOfBalls,self.listOfBalls[i].pos,self.numCell,0)