我写错了程序.
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
#some code
if (y>(h*2/3)):
#some code
else:
#some code
return (newPic)
当我执行这个程序时,第一个if语句if(y< h / 3):被忽略,所以它运行就像第一个if不存在一样.
if (y>(h*2/3)):
#some code
else:
#some code
我发现编写代码的正确方法是这样的:
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
#some code
elif (y>(h*2/3)):
#some code
else:
#some code
return (newPic)
但是,我的问题是;
在第一个代码中 – 为什么绕过第一个if语句?