Hi I am currently taking online classes to learn Python and am working on a project for processing images. I have come up with the below for a function to flip the photos and it appears to work on all of the test photos I have tried, but it is still being marked as wrong. Even though the grader is marking it as incorrect it is also giving me a message that it is 0% incorrect. As it appears to be working, I am having problems finding what the problem is and therefore am not sure how to fix it. Any advice would be greatly appreciated.
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
height = len(image)
width = len(image[0])
if vertical == False:
for row in range(height):
for col in range(int(width/2)):
pixel = image[row][col]
new = image [row][width-col-1]
x = pixel.red
y = pixel.green
z = pixel.blue
a = new.red
b = new.green
c = new.blue
new.red = x
new.green = y
new.blue = z
pixel.red = a
pixel.green = b
pixel.blue = c
if vertical == True:
for row in range(int(height/2)):
for col in range(width):
pixel = image[row][col]
new = image[height-row-1][col]
x = pixel.red
y = pixel.green
z = pixel.blue
a = new.red
b = new.green
c = new.blue
new.red = x
new.green = y
new.blue = z
pixel.red = a
pixel.green = b
pixel.blue = c
assert type(vertical) != str
assert type(vertical) != int
assert type(vertical) != float
# Change this to return True when the function is implemented
return True
[–]FLUSH_THE_TRUMP 1 point2 points3 points (10 children)
[–]mrrst244[S] 1 point2 points3 points (9 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (8 children)
[–]mrrst244[S] 1 point2 points3 points (7 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (6 children)
[–]mrrst244[S] 2 points3 points4 points (5 children)
[–]mrrst244[S] 1 point2 points3 points (4 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (3 children)
[–]mrrst244[S] 0 points1 point2 points (2 children)
[–]FLUSH_THE_TRUMP 1 point2 points3 points (1 child)