JES,嵌套if语句无法正常工作

时间:2017-10-19 15:18:50

标签: python jython jes

我一直遇到由于嵌套的If then语句无法正常工作而导致的运行时错误。对JES不太熟悉,所以我为什么要寻求帮助。基本上,(参见下面的源代码)我的newX(使用w。函数randrange来生成新的xy coords)和newY如果超过599或者不足,那么将var设置为0.好吧,我看到了

        getPixel(picture,x,y):y(= -22)小于0或大于高度     (= 599)     错误值是:     不适当的参数值(正确类型)。     尝试将参数传递给函数时发生错误。     请检查E:\ dOX \ HW \ INF 120 \ e_Project5.py的第39行

from random import *
def main( ):
   #draw
   pic = makeEmptyPicture(600, 600, white)
   show(pic)

#for the 4 boxes 
boxCount = 0
#while statement to draw
while boxCount < 4:
   addRectFilled(pic, randrange(0,576), randrange(0,576), 25, 25, red)
   addArcFilled(pic, randrange(0,576), randrange(0,576), 10, 10, 0, 360, blue)
   boxCount = boxCount + 1
repaint(pic)

newX = 0
newY = 0
oldX = 0
oldY = 0
robotcount = 0
finished = 0 
safe = 0 
triggered = 0
while robotcount < 750 or finished != 1 or safe != 1 or triggered != 1:
   oldX = newX
   oldY = newY
   newX = newX + randrange(-25, 26)
   newY = newY + randrange(-25, 26)
   if newX > 599 or newX < 0:
      newX = 0
   elif newY > 599 or newY < 0:
      newY = 0
   px = getPixel(pic, newX, newY)
   color = getColor(px)
   if color == red:
   triggered = 1
      printNow("trig")
   elif color == blue:
      safe = 1
      printNow("safe")
   elif robotcount == 750:
      finished = 1
      printNow("Fin")
   addLine(pic, oldX, oldY, newX, newY, black)
   robotcount = robotcount + 1

1 个答案:

答案 0 :(得分:0)

我怀疑问题来自**elif** newY > 599 or newY < 0:,这意味着如果触发了先前的测试(newX > 599 or newX < 0),则不会测试newY。将elif替换为if,它应该有效。