Question: Need some help with python code for returning the value when input the row and column Thank you! ## Pascal's Triangle Pascal's triangle is a

Need some help with python code for returning the value when input the row and column

Thank you!

## Pascal's Triangle

Pascal's triangle is a triangular arrangement of numbers where the top row contains the single number `1`, and the values in each following (centered) row are the sum of the value(s) in the row above. The following first five rows of Pascal's triangle should help demonstrate the idea:

1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 By convention, the rows and columns of Pascal's triangle are numbered starting from 0 note that the 0th column of every row contains the value 1. To aid in the computation of edge cases (columns in rows that do not have two values above them), it is also convenient to imagine that there are columns in row 0 extending off in both directions that contain 0s. I.e., we might envision the first row of Pascal's triangle as follows:

... 0 0 0 1 0 0 0 ... 1 1 1 2 1 1 3 3 1 1 4 6 4 1

Wolfram Mathworld has a good writeup on the [properties and provenance of Pascal's Triangle](http://mathworld.wolfram.com/PascalsTriangle.html).

Complete the following function, which returns the value to be found in a given row and column of Pascal's triangle.

def pascal(row, column):

# your code here

#Below are generating pascal's triangle

# generate the first 10 rows of Pascal's Triangle for row in range(10): print('{: ^45}'.format(' '.join(str(pascal(row, col)) for col in range(row+1))))

#below are testing units

# (5 points)

from unittest import TestCase

tc = TestCase()

tc.assertEqual(pascal(0, 0), 1) tc.assertEqual(pascal(1, 0), 1) tc.assertEqual(pascal(2, 1), 2) tc.assertEqual(pascal(5, 1), 5) tc.assertEqual(pascal(5, 2), 10) tc.assertEqual(pascal(10, 5), 252)

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!