Search⌘ K
AI Features

Letting Edward Go Free

Explore how to use Python loops and conditional statements to teach Edward to navigate paths with bends and obstacles. Learn to implement functions like front_is_blocked and trash_present, enabling Edward to turn, detect trash, and complete his journey. This lesson helps you deepen your understanding of loops, conditionals, and function usage in Python programming.

Previously, we provided Edward with the capability to travel on a straight path until the path ended. It was accomplished by making a simple while loop with the stopping condition of a blockade and moving otherwise as shown in the widget below.

Python 3.10.4
while goal_not_achieved():
move()

Turning at a bend

The code we wrote worked fine. However, the paths we have to travel won't always be straight. There will be bumps, hurdles, and bends, and we need to prepare Edward for that. ...