The Logic PuzzleLearning If-Else Statements in Python!

PixelPup is pretty proud that he did find the three clues. His Python skills are improving. But the bone is still so far!
He walked in and around the backyard to find the magical bridge – it was hidden behind bushes. PixelPup is excited! But the bridge is locked it needs a magic key to unlock!
PixelPup remembers from Episode 2: Variables and Values that he can use variables in python code to store these clues!
He gets a note near the bridge, which says, If you have found the feather, found pawprints and found a carrot then magic key is nearby!
PixelPup is excited and runs back to his computer to make his python code, remember this!
- Learn about Logic statements in python 🧠
- Use the variables to create logic 💾
- Print the key to the screen 🖥️
🐾 The Logic Puzzle

Now PixelPup stands at the bridge where a sign says:
“If you have the magic key, you may cross. Else, you must turn back.”
Using what he learned, PixelPup writes the code in python:
if has_magic_key:
print("PixelPup crosses the bridge safely!")
else:
print("PixelPup turns back and searches for the key.")
So the code above is a simple statement to print – PixelPup croses the bridge safely – only if he has the magic key else computer will print “PixelPup turns back and searches for the key”. So that is how the logic works – that is what we use if-else for.
It is same as how you talk in english as simple as that!
⚠️ Also fun fact! The has_magic_key is a variable, remember variables that we did learn in the previous chapter?
and
operator).♣ If all clues are found,
has_magic_key
becomes True
.💎 The if-else statement helps PixelPup decide what happens next.
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 clues and click on the ▶️ button when you are ready to run the command and you will see it showing up on the right side!
Now that PixelPup has been able to solve his challenge through the code above, lets have a small challenge for you – can you create a variable in python that says make_key_glow and when the value :
make_key_glow = True
Then make the computer print – if make_key_glow is true then print “Its a glowing key!!” else it says “Sorry! The glow is missing”
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
Let your imaginations free! We are curious on what you have found from the clues. Will you like to draw what lies ahead of the bridge?
PixelPup loves fan art!! You will be able to see that on our instagram pages too
♣ You can reuse and print stored data
💎 Coding is getting easier, isn’t it? ⌨️
The Endless MazePixelPup enters an endless maze filled with repeating paths and obstacles. To find the exit, PixelPup needs to repeat actions until he reaches the goal — and that’s where Python loops come in!

[…] The Logic PuzzleNext time, PixelPup faces a tougher challenge:Which clue is the most important?Time to learn about if statements and decisions in Python! […]
[…] Missing cluesPixelpup is going on with his investigation journey- so stay tuned.You’ll help PixelPup remember clues using… 🧠 variables!Stay tuned! Or better yet, bookmark this page so you don’t miss the next step in your coding adventure! […]