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, pretty_pascal_triangle, started below for you
The function again takes a single parameter n 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 tri_string, which is what is returned.
Sample output:
print(pretty_pascal_triangle(2))
should produce
1
11
121
Test your result by calling print(pretty_pascal_triangle( 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 pascal_triangle(n)
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 row/list 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 pretty_pascal_triangle(n):
Create a nicely-formatted Pascal's triangle to a specified depth.
Parametersn}:\mathrm{ int
how many rows to print, must be greater than or equal to 1
Returnsstr
nicely formatted string representation of the triangle
"""
tri_string =''raise NotImplementedError()
return tri_string
Task Finish implementing a final function, pretty

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!