我是第一次上编程课,所以很新。我在试着数一张照片中的黑色像素,但我被卡住了。到目前为止,我得到的是:
def main():
#create a 10x10 black picture
newPict = makeEmptyPicture(10, 10)
show(newPict)
setAllPixelsToAColor(newPict,black)
#Display the picture
show(newPict)
#Initialize variabl countBlack to 0
countZero = 0
for p in getPixels(newPict):
r = getRed(p)
b = getBlue(p)
g = getGreen(p)
if (r,g,b) == (0,0,0):
countZero = countZero + 100
return countZero
kedar和deets如何指出,您的返回值在for中,因此,在第一个像素中,它将返回countZero的值,而不是在整个图像上循环,只需修复缩进就可以了:
相关问题 更多 >
编程相关推荐