简体   繁体   English

运行我的python模块的程序在while循环之后总是在第一行返回语法错误

[英]A program running my python module always returns a syntax error on the first line after a while loop

I'm a beginner at python with experience in Java having to write a python module for a Virtual robot challenge for my high schools MESA(A technology based competition) club. 我是python的初学者,具有Java经验,必须为我的中学MESA(基于技术的比赛)俱乐部编写用于虚拟机器人挑战的python模块。 I have been trying to solve this weird problem for days and I only have 6 hours left to fix all the bugs in my code! 几天来,我一直在尝试解决这个怪异的问题,仅剩6个小时即可修复代码中的所有错误! The "invalid syntax" always occurs on the first line after a while loop here is the relevant information: Keep in mind that values have been properly added to the lists “无效语法”总是出现在while循环之后的第一行,此处是相关信息:请记住,值已正确添加到列表中

Relevant code: 相关代码:

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)

Relevant error: 相关错误:

File "L:\controllers\controller_zigzag.py", line 35
i=2+2
^
SyntaxError: invalid syntax

While loops should have a colon on them, such as with: While循环应在其上加一个冒号,例如:

while examinecount < max (interestpoint):

just like your if statements further down. 就像您的if语句进一步向下移动一样。 And, as an aside, it's not C - you don't need parentheses around the entire conditional. 顺便说一句,它不是C-您不需要在整个条件周围加括号。

语法错误是必须在循环后放置一个冒号,并且括号不平衡: while (examinecount<(max(interestpoint)) -> while (examinecount<(max(interestpoint))):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM