Mentor Stage 1

Coding5s / Pillar 2 / Stage 01 Mentor

The Safe Guide

Practice Mentor

The Safe Guide supports the learner during early practice without taking over the task. For useful feedback, the learner should show a real attempt, briefly explain what is confusing them, and ask a specific question about the concept they are practicing.

ATTEMPT EXPLAIN ASK REASON WITH MENTOR
HOW TO USE THIS MENTOR
01 Generate and copy the Stage 1 Mentor Prompt from the Coding5s Creator Kit.
02 Paste the Mentor Prompt into your AI chat.
03 Immediately after it, paste your own attempt, describe what is frustrating or confusing you, and ask one specific question.
EXAMPLE / STUDENT MESSAGE

The example below intentionally contains a realistic beginner mistake from Topic #23.

Student: I’m getting frustrated because this looks right to me, but Python stops at else if and won’t even run. I thought I understood the three branches from the lesson.

Question: Why does Python reject else if here, and how should I think about the difference between if, elif, and else as one decision chain?

Python / Student Attempt
def sensor_alert(temp=20.5):
    print("Sensor reading in Celsius:", temp)
    if temp > 35.0:
        return "Overheating!"
    else if temp < 0.0:
        return "Freezing!"
    else:
        return "Normal Range"

print("Final Alert:", sensor_alert(40.2))
Reference interaction: The student is not asking the AI to simply fix the program. They provide an attempt, expose their confusion, and ask about the underlying mental model so the mentor can guide the reasoning before revealing a solution.

What happens next? When you paste these questions and your code immediately after the Mentor Prompt, you receive feedback like the example shown below.

🎓 Mentor Stage 1 | Topic #23 | Practice | Python Core & Scripting | 📊 Level: Intermediate

Topic: Implement multi-way conditional decision paths using if, elif, and else.

Hey there! Take a deep breath, and don’t worry, we have all been there. Staring at an else if block wondering why the computer is suddenly rebelling is basically a rite of passage for every developer. Your logic is actually spot on, and it’s clear you understand how the decision chain should flow. We just have a tiny language-specific quirk to iron out!

Since you asked a great question about the mechanics of the decision chain, let’s look at the absolute bare bones of it before we fix your script.

⚛️ Cápsula Atómica:

Python evaluates if first, tries elif next, and uses else as the final catch-all.

Python
x = 5                # Input
if x > 10:           # Core -> First check
    y = "Big"
elif x > 3:          # Run -> Second check (only if the first was False)
    y = "Mid"
else:                # Final fallback (only if ALL above were False)
    y = "Small"
print(y)             # Salida: Mid

🎯 Desafío Espejo: Mentally trace this snippet if x = 2. What does y become?

Phase 1: Socratic Hint

It’s fantastic that you articulated your frustration—that’s how we build strong mental models. You are absolutely right to think of if, elif, and else as one single decision chain.

Think of it like a strict bouncer at an exclusive club.

  • The if is the VIP list. He checks that first. If you are on it, you go in, and he stops checking.
  • The elif (Python’s version of “else if”) is the guest list. He only checks this if you weren’t a VIP.
  • The else is the general admission line. If you didn’t match the other two, this is where you automatically end up.

If you use multiple separate if statements instead, you are cloning the bouncer. Now you have three bouncers, and they will all check your ID independently, which might lead to multiple doors opening when you only wanted one!

🔍 Code Observations:

  • Line 5: You used else if. Many languages (like JavaScript or C++) use this, but Python likes to keep things short and uses a specific contracted keyword for it.
  • Line 8/9: Look closely at the very end of your script: return "Normal Range"print(...). Python needs these to be on separate lines so it knows when one command ends and the next begins.

🧠 Socratic Question:

If Python didn’t have a contracted keyword for else if, and you literally had to use the word else followed by a completely new if block inside of it, how would that change the indentation of your code if you had 5 different conditions to check?

🚀 Next Step:

Check the official Python documentation or your lesson notes for the exact keyword Python uses to say “else if” without adding new indentation blocks, and hit ‘enter’ right before your final print statement!

🛑 THE EXPLANATION GATE 🛑 Before scrolling down to see the Master Code, articulate WHY you think your logic failed. Copy-pasting without understanding builds Epistemic Debt.

Phase 2: Full Solution

Your logic was fundamentally sound. Here is your exact code with just the syntax corrected to make Python happy!

Python
def sensor_alert(temp=20.5):
    print("Sensor reading in Celsius:", temp)
    if temp > 35.0:
        return "Overheating!"
    elif temp < 0.0:  # FIXED: Replaced 'else if' with Python's built-in 'elif' keyword
        return "Freezing!"
    else:
        return "Normal Range"

print("Final Alert:", sensor_alert(40.2)) # FIXED: Moved print to a new line

Symbol Breakdown:

  • if: The mandatory start of any conditional chain. It evaluates a boolean expression.
  • elif: Short for “else if”. It ties directly to the if above it. Python will only check this if the preceding if (and any preceding elifs) evaluated to False.
  • else: The optional fallback. It catches everything that slipped through the if and elif checks. It never takes a condition of its own.

⚠️ Common Mistakes:

  • Using else if: Developers coming from other languages frequently type else if. In Python, this throws a syntax error. Always use elif.
  • Missing the Colons: Forgetting the : at the end of the if, elif, or else line.
  • Using if instead of elif: Stacking multiple if statements instead of using elif means Python checks every single one, even if an earlier one was already True. This is a massive source of logical bugs!

🏋️ Mini-Challenges:

  1. Extend the Chain: Add another elif condition to check if the temperature is exactly 20.5 and return "Optimal!". Where does it need to go in the chain?
  2. Reverse the Logic: Try rewriting the function so that the very first if checks for the “Normal Range” (between 0.0 and 35.0), and the else handles the extreme temperatures.

Coding5s Mentor System — Eliminating Epistemic Debt

Scroll to Top