The Endless Maze!Learning Loops in Python!

After solving the last riddle, PixelPup wagged his tail with joy as the forest revealed a hidden bridge. Glowing softly beneath it was the Magic Key 🗝️. As soon as PixelPup picked it up, the clouds parted and revealed a stone path leading to a huge hedge maze. A sign outside read:
“Only those who understand repetition may enter.”
“Hmm… What does that mean?” barked PixelPup. He had a feeling he’d need to do the same thing more than once…
- What loops are and why we use them 🌀
- How to use a
for
loop to repeat actions in python - How to use a
while
loop to keep going until a goal is reached
These are like magic spells to help PixelPup escape the maze!
🐾 The Endless Maze

PixelPup needs to walk through a series of steps over and over. Instead of typing each move again and again, we use a loop!
Loop is what we call in computer language for repeating the same task again and again. In this case, pixel pup has to move forward for 100 steps – so you do not want to type move forward a 100 times to reach your destination.
Here’s an example using a for
loop:
steps = ["forward", "left", "forward", "right", "forward"]
for move in steps:
print("PixelPup goes", move)
print("PixelPup found the glowing key! 🗝️")
In this example, PixelPup needs to follow five steps in the maze:
👉 Forward, Left, Forward, Right, Forward
When we run the code, it tells PixelPup what to do:
PixelPup goes forward
PixelPup goes left
PixelPup goes forward
PixelPup goes right
PixelPup goes forward
We use something called a loop to do this easily without typing the same thing again and again!
Here’s how it works:
- The
for
loop goes through each move in a list and tells PixelPup what to do. - The special words you need are:
for move in steps:
— and it repeats for each word in your list!
You can also use a while
loop, which keeps repeating something until a condition is true.
energy = 5
while energy > 0:
print("PixelPup moves one step in the maze")
energy -= 1
print("PixelPup is out of energy! Time to recharge! ⚡")
So the above code will continue pushing the pixel up one step until the variable energy is zero.
Also note that we are reducing energy by 1 – but that is an arithemetic operation for a future episode!
Loops help PixelPup save time and stay efficient — just like real coders!
♣ There are two methods to create repetition – for loop and while loop.
💎 The loops make your life simpler and your code shorter!
We are using our re-using the print super power here as well as variables. so lets go pups! So lets try that out here in the python playground below – so type your code and click on the ▶️ button when you are ready to run the command and you will see it showing up on the right side!
🧠 Can you create your own list of steps for PixelPup?
- Add more directions to the
steps
list. - Try using a
while
loop to move until PixelPup reaches a goal. - Add fun prints like “Oops! Dead end!” or “Jump over rock!”
Make the maze your own!
Try testing your python code on the above playground and if it works good then Love to hear it – add a comment with your code!
🎨 Bonus Activity – Build your own Maze
PixelPup made it through his maze… now it’s your turn!
🧩 Create a paper maze or use blocks, LEGO, or even pillows on the floor.
🖍️ Draw PixelPup at the start and place the magic key at the end!
Then try this:
- Pretend you’re PixelPup 🐶 and walk through your maze using your own if-else rules.
- For example:
- If there’s a wall, turn right
- If the path is clear, move forward
- If you see a carrot 🥕, jump!
💡 Want a coding challenge too?
Write a new program in Python with your own maze logic, using different paths like path_forward
, path_back
, and path_diagonal
.
PixelPup loves fan art!! You will be able to see that on our instagram pages too
♣ You can now write professional code using python loops!
💎 Our pup gets one step closer to his missing bone ⌨️
The Clue CollectorPixelPup will learn how to store clues using lists and dictionaries!
He’s getting closer to solving the big mystery…
