Python Range Stack Overflow Error Recursive Function Math