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 a list that only contains the number the second element will be the case the list containing and etc.
More concretely, the value returned by pascaltriangle should be the list
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 pascaltriangle, 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 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 singleelement list with the number one:
Subsequent rows should be able to be generated using the pascalrow function you've already defined
Build up this list of lists in the provided tri variable, which is returned by the function.
For example,
printpascaltriangle
should return
Save your resulting list of lists in the variable called tri.
In : v def pascaltrianglen:
Parametersn : int
the value of n for the last row to be printed. Must be greater than or equal to
Returnslist of lists of integers
first row is the first row of Pascal's triangle Last row is the nth row
where n is determined by n
tri raise NotImplementedError
return tri
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
