我是 Python 新手,我尝试在 reeborg 网站上进行训练,结果进展顺利,但在第 4 关,我尝试了我所知道的一切,但机器人仍然无法正常工作
这是我的代码:
def turn_right():
turn_left()
turn_left()
turn_left()
while not at_goal():
if front_is_clear():
while front_is_clear():
if not wall_on_right():
turn_right()
move()
turn_right()
move()
if wall_on_right():
turn_left()
else:
if not wall_on_right():
turn_right()
move()
turn_right()
if wall_on_right():
turn_left()
while wall_on_right():
move()
有人可以帮助我吗?
观察你的程序执行:当 Reeborg 到达世界之巅并且世界边界(即一堵墙)扰乱你的逻辑时,就会发生错误。您试图在一组复杂的 if/while 条件中做太多事情。
将代码分解为更多单独的函数,每个函数包含一组 if/else 指令,或一个 while 循环。
然后尝试将以下一般步骤串联起来:
重复步骤 1 至 4,直到达到目标。