Fix formatting issues for Pascal

This commit is contained in:
lolabird 2024-02-29 11:48:18 -07:00
commit 16a2c25356

View file

@ -3,13 +3,26 @@
# Problem 13
def createTriangle(numRows):
triangle = []
if numRows < 0:
return
else:
for i in range(numRows+1):
spaces = (" "*(numRows-i))
nums = f"{createRow(i)}"
print(spaces + nums)
triangle.append(createRow(i))
lastRow = triangle[-1]
numWidth = len(str(max(lastRow))) + 1
triWidth = numWidth * len(lastRow)
for row in triangle:
triStr = ""
for num in row:
numStr = str(num)
triStr += numStr + " " * (numWidth - len(numStr))
print(triStr.center(triWidth))
def createRow(currentRow):
@ -19,9 +32,7 @@ def createRow(currentRow):
coefficient = getbinomial(currentRow, i)
row.append(coefficient)
result = " ".join(map(str, row))
return result
return row
def getbinomial(n, k):
numerator = factorial(n)