<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dragend(self, event):
 """ Handles the end of a drag action. """

        x_range = [self.begin_drag.x//self.col_width, event.x//self.col_width]
        y_range = [self.begin_drag.y//self.row_height,
                   event.y//self.row_height]

        # Check bounds
        for i in range(2):
            for ls in [x_range, y_range]:
                if ls[i] < 0:
                    ls[i] = 0
                if ls[i] >= self.rows:
                    ls[i] = self.rows-1

        for x in range(min(x_range), max(x_range)+1):
            for y in range(min(y_range), max(y_range)+1):
                if x == self.begin_drag.x//self.col_width and \
                   y == self.begin_drag.y//self.row_height:
                    continue
                self.color_square(x*self.col_width, y*self.row_height)
        self.begin_drag = None

        print(len(self.cells), "cells selected")