• Register
0 votes
67 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)

 

3.9k 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.

38.6k points

Related questions

0 votes
3 answers 696 views
696 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 12 views
12 views
Problem : How do I solve it: Runtimeerror: maximum recursion depth exceeded while calling a python object?
asked Jun 15 Siam55 110k points
0 votes
1 answer 24 views
24 views
Problem: Hi there! I have written the following code in Python which is intended to find the number of letters in the spelling of a number: def count(number): letters = 0 num_string = str(number) print(len(num_string)) if len(num_string) is 1: if number == 1 or ... this one. I do not understand what is causing this error. Please help me understand the cause of the error and resolve it. Thank You!
asked May 29 Code Learner 10.5k points
0 votes
1 answer 15 views
15 views
Problem: Runtimeerror: maximum recursion depth exceeded in cmp.
asked Jun 26 Rada Gracelynn 104k points
0 votes
1 answer 8 views
8 views
Problem: What am I going to do about it : Runtimeerror maximum recursion depth exceeded in comparison?
asked Jun 23 Nahil 128k points
0 votes
1 answer 28 views
28 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 13 views
13 views
Problem: Maximum recursion depth exceeded in comparison python.
asked Jun 26 Rada Gracelynn 104k points
0 votes
1 answer 12 views
12 views
Problem: Is there anyone who knows how to fix this problem : Python maximum recursion depth exceeded in comparison?
asked Jun 25 Mezbah 130k points
0 votes
1 answer 6 views
6 views
Problem: I'm unable to identify the issue and need assistance: Recursionerror: maximum recursion depth exceeded while calling a python object?
asked Jun 14 Shima 126k points
0 votes
1 answer 2 views
2 views
Problem: Maximum recursion depth exceeded in comparison
asked Jul 9 Hridoy 19.2k points