Fix formatting issues for Pascal
This commit is contained in:
parent
86f594cd9a
commit
16a2c25356
1 changed files with 17 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue