I'm writing a simple class that generates the first n
lines of the Pascal Triangle using recursion:
class PascalTriangle:
"""Returns the first n lines of the Pascal Triangle. Recursive."""
def __init__ (self, n):
assert(n > 0)
self.lst[0][0] = 1
self.lines = n
calculate (1)
def __call__(self, n):
assert(n > 0)
self.lst[0][0] = 1
self.lines = n
calculate (1)
def calculate (self, k):
if k == self.lines:
return self.lst
else:
row = [ ]
row.append(1) # <------- line 45
for i in range(1, k-1):
row.append(self.lst[k-1][i-1] + self.lst[k-1][i])
row.append(1)
self.lst.append(row)
calculate(k+1)
def printTriangle(self):
for row in self.lst:
print(row)
ps = PascalTriangle(2)
ps.printTriangle()
ps3 = PascalTriangle()
ps3(3)
ps3.printTriangle()
I'm getting the following error:
line 45
row.append(1)
.......................^
IndentationError: unindent does not match any outer indentation level
It has been very frustrating as I can't really see any problems in the indentation. What am I not getting here?