Implement function pixels() that takes as input two-D list of nonnegative intege
ID: 3547225 • Letter: I
Question
Implement function pixels() that takes as input two-D list of nonnegative integers entries(representing the values of pixels of an image) and returns the number of entries that are positive (ie the number of pixels that are not dark). you function should work on 2D lists of any size.
>>>x=[[0,156,0,0],[34,0,0,0],[23,123,0,34]]
>>>pixels(x)
5
>>>x=[[123,56,255],[34,0,0],[23,123,0],[3,0,0]]
>>>pixels(x)
7
Explanation / Answer
#x=[[0,156,0,0],[34,0,0,0],[23,123,0,34]]
def(pixels(list)):
count=0
for y in list:
for z in range(0,len(y)):
if y[z]>0:
count=count+1
print(count)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.