Question
Pascals triangle is an infinite two-dimensional pattern of numbers whose first five lines are illustrated in Figure 10.22. The first line, line 0, contains just
Pascals triangle is an infinite two-dimensional pattern of numbers whose first five lines are illustrated in Figure 10.22. The first line, line 0, contains just 1. All other lines start and end with a 1 too. The other numbers in those lines are obtained using this rule: The number at position i is the sum of the numbers in position i 1 and i in the previous line.
Using Python, implement recursive function pascalLine() that takes a nonnegative integer n as input and returns a list containing the sequence of numbers appearing in the nth line of Pascals triangle.
>>> pascalLine(0) [1] >>> pascalLine(2) [1, 2, 1] >>> pascalLine(3) [1, 3, 3, 1]
Please provide source code and program execution
4 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started