• Register
0 votes
55 views

Problem :

I am trying to write my first program in Vpython and I have to make the simulation of mixing two gases. First I had the problem with borders, but now when my balls(that represents a gas particles) stay within a border there is the sth different wrong. After the few seconds I get the error, which is shown as below

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 somebody think of the way to simplify the function?

I run my function it while loop:

while 1:
rate(20)
for j in range(0,len(self.listOfBalls)):
self.listOfBalls[j].pos=poruszanie(self.listOfBalls,self.listOfBalls[j].pos,self.numCell,0)

 

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

It occurs because the call to poruszanie results in to another call to poruszanie, incrementing a recursion depth by 1. A second call results in another call to a same function. That keeps happening over and over again, each time incrementing a recursion depth.

Now, a usable resources of the program are limited. Each function call takes the certain amount of space on a top of what is called a stack. If a maximum stack height is reached, you get the stack overflow error.

9 7 4
38,600 points

Related questions

0 votes
3 answers 631 views
631 views
Problem : I am getting below error maximum recursion depth exceeded while calling a python object
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 63 views
63 views
Problem: I am new to python programming and I am little bit bit confused about some things like I wrote a code: def random(): a = random.randint (0, x+1) b = random.randint (0, y+1) c = random.randint (0, z+1) outer_function(a,b,c ... recursion depth exceeded while calling a Python object IndentationError: expected an indented block I am confused about those things, why is this error shown to me ?
asked Mar 22, 2020 LizzyM 6.1k points
0 votes
1 answer 12 views
12 views
Problem: How to I Solve this: runtimeerror maximum recursion depth exceeded in cmp HELP! I need help understanding this: runtimeerror maximum recursion depth exceeded in cmp Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 7 Mashhoodch 13k points
0 votes
1 answer 8 views
8 views
maximum recursion depth exceeded while calling a python object
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 12 views
12 views
recursionerror: maximum recursion depth exceeded in comparison
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 2 views
2 views
Question: I have a Computer Science Midterm tomorrow and I need help determining the complexity of these recursive functions. I know how to solve simple cases, but I am still trying to learn how to solve these harder cases. These were just a few of the example problems that I could not figure out. Any ... printf("%d, %d\n",m, o); } else { recursiveFun4(n-1, m+1, o); recursiveFun4(n-1, m, o+1); }
asked 2 days ago Atik03 5.9k points
0 votes
1 answer 8 views
8 views
Problem: How to solve: T(n) = T(n/2) + T(n/4) + T(n/8) + (n)
asked Mar 21 ummesalma 24.5k points
0 votes
1 answer 9 views
9 views
Problem: Does anyone know that how to search multidimensional array for key and return value?
asked Mar 12 Ifra 24.4k points
0 votes
1 answer 8 views
8 views
Problem: I've got error message > chromedriver' executable needs to be in path.
asked Apr 1 Azlan2020 2.3k points
0 votes
1 answer 30 views
30 views
Problem: I'm new to programming and started with Python about two months ago and am going over Sweigart's Automate the Boring Stuff with Python text. I'm using IDLE and already installed the Selenium module and the Firefox browser. Whenever I tried to run the webdriver function, I get this: from selenium import webdriver browser = webdriver.Firefox()
asked Jan 6 Mashhoodch 13k points