Code for Life Community
  • ๐Ÿ’›Welcome
  • ๐Ÿ“…Release Notes
  • โค๏ธBecome a Contributor
  • ๐ŸชดIndustry Experience
  • ๐Ÿ†Wall of Fame
  • ๐Ÿ“ฆRepositories and Packages
  • ๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟNational Curriculum alignment
  • ๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟNational Curriculum alignment
  • โ„น๏ธGlossary
  • COMMUNICATIONS
    • ๐Ÿ“–Publications
  • ๐Ÿ—ž๏ธNewsletters
    • ๐ŸŽŠSpring 2025
    • ๐ŸŒทBett show 2025
    • ๐ŸŽ„December 2024
    • ๐ŸAutumn 2024
    • ๐ŸŒปSummer 2024
    • ๐ŸฐSpring 2024
    • โ„๏ธWinter 2024
    • ๐ŸŽ„December 2023
    • ๐ŸAutumn 2023
    • ๐ŸŒปSummer 2023
    • ๐ŸŒทSpring 2023
    • ๐ŸŽ„December 2022
    • ๐ŸAutumn 2022
    • ๐ŸŒปSummer 2022
    • ๐ŸŒทSpring 2022
    • ๐ŸŽ„December 2021
  • ๐ŸงฉNewsletter challenges
    • ๐Ÿค–Ocado Robot Debugging Challenge!
  • ๐Ÿค–Books of Robots
  • Community resource hub
    • ๐Ÿ’ปHow do Computers work?
    • ๐Ÿ”Safety online: Passwords and Security
    • ๐Ÿค–The World of Robotics
    • ๐ŸฆพCareers in technology
      • ๐Ÿ“ƒCareers posters
      • ๐Ÿ“ฝ๏ธCareer based videos
  • Software Developer Guide
    • ๐Ÿ’ปDev Environment Setup
    • ๐Ÿ”Code Promotion Strategy
    • ๐Ÿ’ฟBack End
      • โ„น๏ธOverview
      • โœ๏ธCoding Patterns
      • ๐ŸงชTesting Strategy
    • ๐Ÿ–ฑ๏ธFront End
      • โ„น๏ธOverview
      • โœ๏ธCoding Patterns
      • ๐ŸงชTesting Strategy
  • Links
    • Code Workspace
    • Visit our Site
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Newsletter challenges

Ocado Robot Debugging Challenge!

PreviousNewsletter challengesNextBooks of Robots

Last updated 29 days ago

Was this helpful?

๐Ÿงฉ
๐Ÿค–

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:

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()

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!