Question: Problem 5. (Pascals Triangle) Pascals triangle Pn is a triangular array with n + 1 rows, each listing the coefficients of the binomial expansion (x

Problem 5. (Pascals Triangle) Pascals triangle Pn is a triangular array with n + 1 rows, each listing the coefficients of the binomial expansion (x + y) i , where 0 i n. For example, P4 is the triangular array: 1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

The term Pn(i, j) is calculated as Pn(i 1, j 1) + Pn(i 1, j), where 0 i n and 1 j

Problem 5. (Pascals Triangle) Pascals triangle Pn is a triangular array with

Answer:

$ python pascal . py 10

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

1 8 28 56 70 56 28 8 1

1 9 36 84 126 126 84 36 9 1

1 10 45 120 210 252 210 120 45 10 1

(We are using python 2.7)

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 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 i in range a Lil Fill the ragged list a using the formula for Pascal's triangle a [i][j] ali 11 ali 1] [j] where 0 i, n and 1 j i. for i in range for j in range Write out the ragged list a with elements separated by spaces and each row ending in a newline. for i in range for i in range

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!