Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Created May 2, 2014 01:43
Show Gist options
  • Save pzp1997/1b537a11f29a5bbdc92c to your computer and use it in GitHub Desktop.
Save pzp1997/1b537a11f29a5bbdc92c to your computer and use it in GitHub Desktop.
class PascalsTriangle(object):
def __init__(self):
self.rows = [[1], [1, 1]]
def addRow(self):
row = [1]
for x in range(len(self.rows[-1])-1):
row.append(self.rows[-1][x] + self.rows[-1][x+1])
row.append(1)
self.rows.append(row)
def printRow(self):
for num in range(len(self.rows[-1])):
print(self.rows[-1][num], end=" ")
print()
def onLoad(self):
for row in range(len(self.rows)):
for num in range(len(self.rows[row])):
print(self.rows[row][num], end=" ")
print()
PT = PascalsTriangle()
PT.onLoad()
while True:
PT.addRow()
PT.printRow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment