# Runtimeerror: maximum recursion depth exceeded while calling a python object

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+choice([-1,0,1]),position+choice([-1,0,1]),0),numCell,1)File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position+choice([-1,0,1]),position+choice([-1,0,1]),0),numCell,1)File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position+choice([-1,0,1]),position+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)``````

## 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

696 views
Problem : I am getting below error maximum recursion depth exceeded while calling a python object
12 views
Problem : How do I solve it: Runtimeerror: maximum recursion depth exceeded while calling a python object?
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!
15 views
Problem: Runtimeerror: maximum recursion depth exceeded in cmp.
8 views
Problem: What am I going to do about it : Runtimeerror maximum recursion depth exceeded in comparison?
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!
13 views
Problem: Maximum recursion depth exceeded in comparison python.