Question: Now we'll create a function that creates the whole triangle structure, formatted as a list of lists. The first element will be the first row

Now we'll create a function that creates the whole triangle structure, formatted as a list of lists. The first element will be the first
row (n=0, a list that only contains the number 1), the second element will be the n=1 case (the list containing 1 and 1), etc.
More concretely, the value returned by pascal_triangle(3) should be the list [[1],[1,1],[1,2,1],[1,3,3,1]].
Note that indeed, this is a list of lists. Each element is a row of Pascal's triangle, with the zeroth row in the zeroth position.
Task
Finish implementing the function pascal_triangle, started below.
It takes a single integer n as an argument, and generates a list of lists that represent Pascal's triangle to a specified a
depth of n, as a list of lists, with the first being the zeorth row and the last being the nth row.
You will need to know that the first row is simply a single-element list with the number one: [1].
Subsequent rows should be able to be generated using the pascal_row function you've already defined
Build up this list of lists in the provided tri variable, which is returned by the function.
For example,
print(pascal_triangle(3))
should return
[1???11??121?1331]
Save your resulting list of lists in the variable called tri.
In []: v def pascal_triangle(n):
Parametersn : int
the value of n for the last row to be printed. Must be greater than or equal to 0
Returnslist of lists of integers
first row is the first row of Pascal's triangle ([1]). Last row is the nth row
where n is determined by 'n`
'''
tri =[]raise NotImplementedError()
return tri
Now we'll create a function that creates the

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 Programming Questions!