I wrote the program incorrectly.
def changeByThirds(pic): w= getWidth (pic) h = getHeight(pic) newPic = makeEmptyPicture(w,h) for x in range (0,w): for y in range (0,h): pxl = getPixel(pic, x, y) if (y<h/3): #some code if (y>(h*2/3)): #some code else: #some code return (newPic)
When I run this program, the first if if (y<h/3): ignored, so it works as if the first, if not at all.
if (y>(h*2/3)): #some code else: #some code
I found that the correct way to write code was this:
def changeByThirds(pic): w= getWidth (pic) h = getHeight(pic) newPic = makeEmptyPicture(w,h) for x in range (0,w): for y in range (0,h): pxl = getPixel(pic, x, y) if (y<h/3): #some code elif (y>(h*2/3)): #some code else: #some code return (newPic)
However my question is:
In the first code. Why does it bypass the first if statement?
source share