Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# pascal.py: takes an integer n as command-line argument and writes # Pascal\'s

ID: 3862410 • Letter: #

Question

# pascal.py: takes an integer n as command-line argument and writes
# Pascal's triangle P_n.

import stdarray
import stdio
import sys

# Get n from command line, as an int.
n = int(sys.argv[1])

# Construct a 2D ragged list a of integers. The list must have n + 1 rows,
# with the ith (0 <= i <= n) row a[i] having i + 1 elements, each initialized
# to 1.
a = [1]
for i in range(0, n):
    a[i] =

# Fill the ragged list a using the formula for Pascal's triangle
#     a[i][j] = a[i - 1][j - 1] + a[i - 1][j]
# where 0 <= i <= n and 1 <= j < i.
for i in range(...):
    for j in range(..., ...):
        a[i][j] = ...

# Write out the ragged list a, with elements separated by spaces, and each
# row ending in a newline.
for i in range(...):
    for j in range(..., ...):
        ...

Dont use print

Explanation / Answer

def printPascalTriangle(rows):
a1 = [1]
a2 = [1, 1]
triangle = [a1, a2]
row = []
if rows == 1:
a1[0] = str(a1[0])
print(' '.join(a1))
elif rows == 2:
for index in triangle:
for a in range(len(index)):
index[a] = str(index[a])
print((' ')*(2-(a+1)), (' '.join(index)))
else:
for i in range(2, rows):
triangle.append([1]*i)
for n in range(1, i):
triangle[i][n] = (triangle[i-1][n-1]+triangle[i-1][n])
triangle[i].append(1)
for x in range(len(triangle)):
for y in triangle[x]:
s = str(y)
row.append(s)
print((' ')*(rows-(x+1)), (' ' .join(row)))
row = []

you can call this method by passing the command line arugement as parameter.

Ex:-printPascalTriangle(sys.argv[1])