Recall the function definition of creating a 2D list representing a screen of pixels: def create_screen(rows, columns): ''' Creates a screen of rows x columns pixels ''' grid = [] for x in range(rows): grid.append([0] * columns) return grid Complete the following function definition according to the docstring comment and assert examples below: def count_pixels(screen): ''' The parameter screen has arbitrary values and dimension (represented as a 2D list). Return the number of pixels with a value equal to 0. '''
def create_screen(rows, columns): """ Creates a screen of rows x columns pixels """ grid = [] for x in range(rows): grid.append([0] * columns) return grid def count_pixels(screen): """ The parameter screen has arbitrary values and dimension (represented as a 2D list). Return the number of pixels with a value equal to 0. """ count = 0 for row in screen: for item in row: if item == 0: count += 1 return count
Get Answers For Free
Most questions answered within 1 hours.