Reputation: 9
This is my code for the fill karel question. The bot works perfectly and fills all places perfectly but it gets stuck in an infinite loop in the upper shelf or encounters a runtime error
def main():
"""
You should write your code to make Karel do its task in
this function. Make sure to delete the 'pass' line before
starting to write your own code. You should also delete this
comment and replace it with a better, more descriptive one.
"""
while front_is_clear():
put_beeper_line()
while front_is_blocked():
turn_around()
while front_is_clear():
move()
if front_is_blocked():
turn_right()
if front_is_clear():
move()
turn_right()
while front_is_clear():
put_beeper_line()
else:
turn_right()
if front_is_clear():
move()
move()
move()
move()
move()
move()
def put_beeper_line():
while front_is_clear():
put_beeper()
move()
put_beeper()
def turn_right():
for _ in range(3):
turn_left()
def turn_around():
for _ in range(2):
turn_left()
# There is no need to edit code beyond this point
if __name__ == '__main__':
main()
previously it was getting stuck in an infinite loop but now with the provided code it completes the task but encounters a runtime error which the interpreter isnt accepting.
Upvotes: 0
Views: 351