Question: python only with those specific imports only # pascal.py: takes an integer n as command-line argument and writes # Pascal's triangle P_n. import stdarray import
python only with those specific imports only
# 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 = ... # 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. For example, if n = 3, a should be initialized to # [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]. a = [] for i in range(...): a += [...] # 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(..., ...): if j < i: ... else: # end of a row ...
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
