0

I tried making this function to return infinity so I could use it in equations. but I keep getting an error that says something about stack overflow, so that's why I'm asking you guys.

def returnInfinity(num = 1):
  return returnInfinity(num + 1)

INFINITY = returnInfinity()
Skepay
  • 45
  • 7
  • The stack overflow is because you tried to recurse *infinitely*. Each call allocates more of the stack, until you run out of stack (either logically, when you hit Python's default recursion limit, or in reality, if you raise the Python recursion limit and end up running out of actual stack space and Python can't do a thing to help you). Why did you think you could compute infinity by counting up one at a time? No matter how far you count, infinity is further. That's how infinity works. – ShadowRanger Nov 11 '20 at 02:10

1 Answers1

1

Use the math library's math.inf if you're on version 3.5 or above.

import math

print(math.inf)

Otherwise, you can do int("inf") or float("inf").

Inversion
  • 23
  • 6