class Solution:
    def rotate_image(self, image):
        if not self.isValidImage(image):
            raise Exception('Invalid image')
        
        n = len(image)

        for row in range(n//2):
            start = row
            end = n - 1 - row
            for col in range(start, end): # end should not be included, because it is already taken care of in the first iteration
                x = row
                y = col
                prev = image[x][y]
                for _ in range(4):
                    new_row = y
                    new_col = n - x - 1
                    new_cell = image[new_row][new_col]
                    image[new_row][new_col] = prev
                    x = new_row
                    y = new_col
                    prev = new_cell
    
    def isValidImage(self, image):
        n = len(image)
        return n > 0 and len(image[0]) == n

    def print_image(self, image):
        for row in image:
            print(row)

image = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
solution = Solution()
solution.print_image(image)
solution.rotate_image(image)
print('===============')
solution.print_image(image)