# Newsletter challenges

### Ocado Robot Debugging Challenge!

Oh no! The program of an Ocado bot has a bug! This robot is supposed to collect the groceries, but it's not working correctly. Your mission is to debug the Python code and get the robot back on track.

The Grid:

Imagine the maze as a simple grid. Your robot can move in four directions: "up", "down", "left", and "right".

Here's the layout of your grid:

```
# # # # # #
# S - A - #
# - - - - #
# - B - - #
# - - - - #
# C - - E #
# # # # # #
```

*# represents a wall – the robot can't go there.*

*- represents an empty space the robot can move through.*

*S is the robot's starting position.*

*A is the avocado.*

*B is the banana.*

*C is the carrot.*

*E is the delivery exit.*

### The Challenge:

#### **The following Python code has some bugs. Your task is to:**

1. Identify the errors in the code.
2. Correct the errors so the robot can successfully collect the avocado ('A'), banana ('B'), and carrot ('C').
3. The robot should start at 'S' and end at 'E'

Here's the buggy Python code:

{% code overflow="wrap" %}

```python
def robot_path():
    # Initial robot position
    robot_row = 1
    robot_col = 1

    # Items collected
    collected_items = []

    print("Starting the Ocado Bot!")

    # Move to Avocado
    robot_col += 1
    print("Moved Right")
    robot_col += 1
    print(Moved Right)
    if robot_row == 1 and robot_col == 3:
        print("Yummy! Found an avocado!")
        collected_items.append("avocado")

    # Move to Banana
    robot_row += 1
    print("Moved Down")
    robot_col -= 1
    print("Moved Left")
    if robot_row == 3 and robot_col == 1:
        print "Yummy! Found a banana!"
        collected_items.append("banana"

    # Move to Carrot
    robot_row += 1
    print("Moved Down")
    robot_col -= 1
    print("Moved Left")
    if robot_row == 5 and robot_col == 1:
        print("Yummy! Found a carrot!")
        collected_items.append("carrot")

    # Move to Exit
    robot_row += 3
    print(“Moved Right 3 times”)
    if robot_row == 5 and robot_col == 4:
        print(“Yay! Found the delivery exit!”)

    if "Avocado" in collected_items and "banana" in collected_items and "carrot" in collected_items:
        print("Mission Complete! All groceries collected!")
    else:
        print("Oh no! The robot didn't collect all the items.")

# Run the function!
robotpath()


```

{% endcode %}

Debugging Tips:

* Read the code carefully, line by line.
* Think about the robot's starting position and the grid layout.
* Trace the robot's movements based on the code.
* Identify where the robot goes wrong.
* Correct the code to ensure the robot reaches each item.
* Test your corrected code to make sure it works!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.codeforlife.education/newsletter-challenges.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
