Question

Recall the function definition of creating a 2D list representing a screen of pixels: def create_screen(rows,...

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. '''

Homework Answers

Answer #1
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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT