I've wrote a Python program to multiply two numbers recursively. The program is working fine for small digit numbers but when I am increasing the recursive stack to calculate the multiplication of two big numbers having 125 digits each (say) then its not working. The program is crashing and its not printing anything.
class recursionlimit:
def __init__(self, limit):
self.limit = limit
def __enter__(self):
self.old_limit = sys.getrecursionlimit()
sys.setrecursionlimit(self.limit)
def __exit__(self, type, value, tb):
sys.setrecursionlimit(self.old_limit)
def multiply(x,y):
if x<y:
return multiply(y,x)
if y!=0:
return x + multiply(x,y-1)
else:
return 0
def random_number():
number = rt.randint(pow(10,128),pow(10,129))
return number
def main():
x = random_number()
y = random_number()
with recursionlimit(10**9):
output = multiply(x,y)
print(output)
main()