Created
May 2, 2014 01:43
-
-
Save pzp1997/1b537a11f29a5bbdc92c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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