You have problems with indentation and colons.
needs a colon at the end, just before the
following indented block of code.
Also, all code within a block needs to be at
the same level of indentation. In your code, the
last two lines are indented two extra characters.
Here is the fixed code:
# Note indentation
for y in range(0,height): # Note a colon here
for x in range(0,width): # And here
r = getPixel(getRed(source))
g = getPixel(getGreen(source))
b = getPixel(getBlue(source))
average = (r + g + b) / 3
setColor = newColor
# Your code...
Make sure to read about flow control in Python.