Using recursion is generally advised against, as it takes longer that iterating, and can run into what you ran into, a
RuntimeError: maximum recursion depth exceeded. Note you can change the maximum recursion depth, but it is generally advised against, and can lead to stack or memory overflows. In this case, you should iterate.
i = n
if i == 1:
i -= 1
n += i
(This keeps running in the same function call, reducing the addition factor by one each time.)
Or better yet, use a
range (or xrange for Python 2):
for i in range(n): # range(3) is a generator for [0, 1, 2]
n += i
Or better yet, use
return sum(range(n + 1))
Or, even better, use the formula for triangle numbers.
return n * (n + 1) // 2 # Convert to int for Python 2