0
我的功能的目标是收集RGB颜色编号(1-255),找到这三个数字的平均值,并将所有3个RGB值设置为该平均值。我认为我很接近,但有些东西不起作用,我不确定它是什么。for循环中的语法错误
此外,它说该函数的第一行有语法错误。
在此先感谢
def grayScale(source):
path = pickAFile()
source = makePicture(path)
height = getHeight(source)
width = getWidth(source)
sourceY = 0
for y in range(0,height): # Note a colon here
sourceX = 0
for x in range(0,width): # And here
r = getRed(getPixel(source, int(sourceX), int(sourceY)))
g = getGreen(getPixel(source, int(sourceX), int(sourceY)))
b = getBlue(getPixel(source, int(sourceX), int(sourceY)))
average = (r + g + b)/3
newColor = makeColor(average,average,average)
setColor(getPixel(target, targetX, targetY), newColor)
print average
explore(target)
我已经改变了一些东西,这是错误现在我得到我不知道为什么......
错误是:源 名称不全球发现。 找不到本地或全局名称。您需要在尝试以任何方式使用它之前定义函数或变量。
你可以发布所有有问题的代码和错误的堆栈跟踪吗? – 2014-11-23 23:02:08
冒号丢失,缩进关闭。 – kay 2014-11-23 23:02:27
在行尾添加冒号:'对于范围(0,高度)中的y:'和对于范围(0,宽度)中的x':'并且使缩进对于最后两行是正确的。 – kums 2014-11-23 23:02:27