Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago