[英]A program running my python module always returns a syntax error on the first line after a while loop
我是python的初学者,具有Java经验,必须为我的中学MESA(基于技术的比赛)俱乐部编写用于虚拟机器人挑战的python模块。 几天来,我一直在尝试解决这个怪异的问题,仅剩6个小时即可修复代码中的所有错误! “无效语法”总是出现在while循环之后的第一行,此处是相关信息:请记住,值已正确添加到列表中
相关代码:
interestlengthl=list()
interestlengthr=list()
interestpoint=list()
def do_examine(robot):
examinecount=0;
while (examinecount<(max(interestpoint)) <-the while loop
i=2+2 <-a innocent line used as an example, this returned an invalid syntax
maxpoint=max(interestpoint)
tomove=(currentposition-(max[interestpoint]-interestpoint(examinecount)))
robot.step_forward(tomove)
leftscan=robot.sense_steps(robot.SENSOR_LEFT)
rightscan=robot.sense_steps(robot.SENSOR_RIGHT)
if (rightscan==interestlengthr(examinecount):
robot.turn_right()
do_rowscan(robot)
if (leftscan==interestlengthl(examinecount):
robot.turn_left()
do_rowscan(robot)
examinecount+=1
robot.turn_right(2)
currentposition=robot.sense_steps(robot.SENSOR_FORWARD)
robot.turn_right(2)
相关错误:
File "L:\controllers\controller_zigzag.py", line 35
i=2+2
^
SyntaxError: invalid syntax
While循环应在其上加一个冒号,例如:
while examinecount < max (interestpoint):
就像您的if
语句进一步向下移动一样。 顺便说一句,它不是C-您不需要在整个条件周围加括号。
语法错误是必须在循环后放置一个冒号,并且括号不平衡: while (examinecount<(max(interestpoint))
-> while (examinecount<(max(interestpoint))):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.