How to flip a certain area of image from top to bottom.

def flip_vertical(image, col_index, row_index, height, width):
   for column in range(col_index, col_index + width):
          for row in range(row_index, (row_index + height) // 2):              
            temp = image[row][column]
            image[row][column] = image[len(image)- row -1][column]
            image[len(image)- row - 1][column] = temp

I can only pass some cases but not all cases. How can I do to fix my code.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

I mean, print out the results of the challenges you fail and look where the difference to the expected result is.
If you pass some and fail others, sounds like your loop is not running the correct number of times.

Also one nice feature of Python is that you can make multiple assignments in one line.
For example, switching the value of two numbers is:

a, b = b, a

So you don’t need to use temp.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.