Question: 1 3 . Add Vertical Flipping Extend your implementation of the function flip to include the case vertical is True. Use an if - statement

13. Add Vertical Flipping
Extend your implementation of the function flip to include the case vertical is True. Use an if-statement to make sure that you do not break horizontal flipping. Your function should flip horizontally when vertical is False and vertically when it is True.
To test out vertical flipping, you will need to execute pictool.py with the vertical option, adding --vertical=True to the end of the command line. For example, executing the command
python pictool.py flip images/Walker.png Walker2.png --vertical=True
should perform the following conversion:
Important: Because you can put anything you want in the vertical option (say --vertical=blue), we recommend that you enforce the precondition for vertical in the function with assert statements.
def flip(image,vertical=False):
"""
Returns True after reflecting the image horizontally or vertically.
All plug-in functions must return True or False. This function returns True
because it modifies the image. By default it reflects the image horizonally,
or vertically if vertical is True.
Parameter image: The image buffer
Precondition: image is a 2d table of RGB objects
Parameter vertical: Whether to reflect the image vertically
Precondition: vertical is a bool
"""
# We recommend enforcing the precondition for vertical
assert isinstance(vertical, bool)
rows = len(image)
cols = len(image[0])
if not vertical:
for row in image:
row.reverse()
else:
image.reverse()
# Change this to return True when the function is implemented
return True

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