🎯 What you will learn
- Combine loops, functions and if/else
- Test your plan step by step
- Debug a mission when it goes wrong
👋 Let’s get started!
A robot is stuck in a maze and needs rescuing! 🚑 Use everything you have learned: functions for moves, a loop for each step of the mission, and if/else to check the sensor before every move.
🪜 Step by step
1. 🗺️ Plan the mission
Write the mission as a list of moves, then loop through the list.
moves = ["forward", "turn_left", "forward"]
for move in moves:
print(move)
2. 🛡️ Check first
Before each move, check the sensor. Only move when the path is clear.
clear = True
if clear:
print("Path clear")
3. 🏁 Report back
At the end, print a message so everyone knows the mission worked.
print("Robot rescued!")
🧪 Try it!
Change the code and press ▶ Run to see what happens. You can’t break anything!
The rescue mission
def move(name, clear):
if clear:
print("Moved", name)
else:
print("Blocked:", name, "- finding another way")
missions = [("forward", True), ("turn_left", True), ("forward", False), ("turn_right", True)]
for name, clear in missions:
move(name, clear)
print("Robot rescued!")🎨 Unplugged activity
🚑 Design your own rescue robot mission on paper: list 5 moves and a sensor check. Test it with a grown-up acting as the robot. Fix any bugs you find!
Fix the mission
def move(name, clear):
if clear:
print("Moved", name)
move("forward", True)
print("Robot rescued!")📖 Key words
Tap a card to flip it over!
- Mission
- A job with a goal 🎯
- Debug
- Finding and fixing a mistake 🐞
- Plan
- Thinking through steps first 🗺️
🏆 Challenge
The robot is blocked on one move. Make the rescue print “Robot rescued!” at the end. Press ▶ Run.
Challenge
def move(name, clear):
if clear:
print("Moved", name)
else:
print("Blocked:", name, "- finding another way")
Knowledge Check Quiz
- Why check a sensor before moving?
- What does a loop over moves do?
- What proves the mission worked?