# RecursionError: maximum recursion depth exceeded in comparison

hey guys, when I wrote this code:

``````def largest_and_smallest(num1, num2, num3):
if (num1<=num2) and (num1<=num3) and (num2<=num3):
min_vel=num1
max_vel=num3
elif (num1 <= num2) and (num1 <= num3) and (num3 <= num2):
min_vel = num1
max_vel = num2
elif (num2<=num1) and (num2<=num3) and (num3<=num1):
min_vel = num2
max_vel = num1
elif (num2<=num1) and (num3<=num2) and (num3<=num1):
min_vel = num3
max_vel = num1
elif (num1 <= num2) and (num3 <= num2) and (num3 <= num1):
min_vel = num3
max_vel = num2
return min_vel, max_vel
largest_and_smallest(num1, num2, num3)
``````

I got this problem:

``````    if (num1<=num2) and (num1<=num3) and (num2<=num3):
RecursionError: maximum recursion depth exceeded in comparison
``````

I’m really don’t understand…
thank you!

Its similar to infinity loop, except this time instead of a loop, you have a function calling itself over and over again.

You nested the function call within the body of the function.

ok. I understand. anyway, I forgot to add another code lines:

``````def check_largest_and_smallest():
min_vel1,max_vel2=largest_and_smallest(17,1,6)
min_vel2, max_vel2=largest_and_smallest(1,17,6)
min_vel3, max_vel3=largest_and_smallest(1,1,2)
min_vel4, max_vel4=largest_and_smallest(1,1,1)
min_vel5, max_vel5=largest_and_smallest(3,2,1)
if (min_vel1==1 and max_vel1==17) and (min_vel2==1 and max_vel2==17) and (min_vel3==1 and max_vel3==2) and (min_vel4==1 and max_vel4==1) and (min_vel5==1 and max_vel5==1):
check= True
else:
check= False
return check
check_largest_and_smallest()
``````

how can I repair it?

Can you post your full code? You call `largest_and_smallest` several times, but i don’t see the function definition anywhere.

I think that I found it here:

``````def largest_and_smallest(num1, num2, num3):
if (num1<=num2) and (num1<=num3) and (num2<=num3):
min_vel=num1
max_vel=num3
elif (num1 <= num2) and (num1 <= num3) and (num3 <= num2):
min_vel = num1
max_vel = num2
elif (num2<=num1) and (num2<=num3) and (num3<=num1):
min_vel = num2
max_vel = num1
elif (num2<=num1) and (num3<=num2) and (num3<=num1):
min_vel = num3
max_vel = num1
elif (num1 <= num2) and (num3 <= num2) and (num3 <= num1):
min_vel = num3
max_vel = num2
return min_vel, max_vel
**largest_and_smallest(num1, num2, num3**
``````

at the last line, I call the inner function.

which inner function? You call the function you are currently executing, which gives recursion

yes. That’s what I mean