Question: Task Finish implementing a final function, pretty _ pascal _ triangle, started below for you The function again takes a single parameter n that gives
Task
Finish implementing a final function, prettypascaltriangle, started below for you
The function again takes a single parameter that gives the depth of the triangle
It will return but not print a string representation of a pascal triangle that is centered about the bottom row.
Numbers in each row should have one space between each. Each row should be centered and have the same width,
which will necessarily be the width of the bottom row.
Save the resulting string in the variable called tristring, which is what is returned.
Sample output:
printprettypascaltriangle
should produce
Test your result by calling printprettypascaltriangle n for various values of n as shown above.
Notes and Hints
There are several ways you could go about this, but here's one path:
Produce the data for the triangle using pascaltriangle
Convert each row of the triangle to a list of strings using the function on each element
Use the join method of strings to convert each rowlist into a single string of numbers separated by single
spaces
Find the width of the bottom row
Use the center method of strings to center each row to the right width
Again ust the join method to combine all the rows together so they are separated by newline characters
In : v def prettypascaltrianglen:
Create a nicelyformatted Pascal's triangle to a specified depth.
Parametersn:mathrm int
how many rows to print, must be greater than or equal to
Returnsstr
nicely formatted string representation of the triangle
tristring raise NotImplementedError
return tristring
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
