Question: USE!!! PYTHON!!! Pascal's triangle is an infinite two-dimensional pattern of numbers whose first six lines are: usual formatting: 1 1 1 1 2 1 1
USE!!! PYTHON!!!
Pascal's triangle is an infinite two-dimensional pattern of numbers whose first six lines are:
| usual formatting: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 | alternate formatting (may be helpful for code): 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 |
The first line, line 0, contains just 1. All other lines start and end with a 1 as well. The other numbers in those lines are obtained using the following rule: the number at position i is the sum of the numbers in position i-1 and i in the previous line. Implement a recursive function pascalLine takes as a parameter a non-negative integer n and returns a list containing the sequence of numbers appearing in the nth line of Pascal's Triangle. The function will have one loop in it to construct the list corresponding to the line returned, but the rest of the work should be done recursively. The following shows some sample runs of the function:
>>> pascalLine(0)
[1]
>>> pascalLine(1)
[1, 1]
>>> pascalLine(2)
[1, 2, 1]
>>> pascalLine(3)
[1, 3, 3, 1]
>>> pascalLine(4)
[1, 4, 6, 4, 1]
>>> pascalLine(7) [1, 7, 21, 35, 35, 21, 7, 1]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
