🧩Newsletter challenges
Last updated
Was this helpful?
Was this helpful?
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()