Mentor Stage 3

Coding5s / Pillar 2 / Stage 03 Mentor

The Logical Scaffold

Complete Mentor

The Logical Scaffold helps the learner connect missing pieces instead of completing them automatically. For useful feedback, the learner should provide their partial implementation, explain where the logic currently stops, describe the result they still need to reach, and ask for guidance on the missing transformation.

INPUT β†’ CURRENT LOGIC β†’ FIND THE GAP β†’ REASON β†’ COMPLETE
HOW TO USE THIS MENTOR
01 Generate and copy the Stage 3 Mentor Prompt from the Coding5s Creator Kit.
02 Work on the incomplete exercise yourself and implement as much of the missing logic as you can.
03 Paste the Mentor Prompt into your AI chat, followed by your partial code and a brief explanation of what already works and where you became stuck.
04 Ask about the missing logical connection instead of asking the AI to complete the entire exercise for you.
EXAMPLE / STUDENT COMPLETION REQUEST

The example below simulates a student who successfully completed part of Topic #23 but cannot connect the remaining input case to the required output.

Student: I’m so close that it’s actually frustrating me. I got the Child and Teen cases working, but age 25 is still coming back as Unknown. I know I’m missing the final part of the decision chain, but I’m second-guessing whether I need another elif or if I’m supposed to use else.

Question: How should I reason from the remaining input cases to the required Adult output so I can decide what belongs in the missing part of the chain? Please guide me through the logic before showing me the completed line.

Python / Current Output
Age 10 is categorized as: Child
Age 15 is categorized as: Teen
Age 25 is categorized as: Unknown
Age 18 is categorized as: Teen
Python / Student Attempt
def categorize_user(age):
    category = "Unknown"

    if age < 13:
        category = "Child"
    elif age < 20:
        category = "Teen"

    return category

users = [10, 15, 25, 18]
for u in users:
    print(f"Age {u} is categorized as: {categorize_user(u)}")
Reference interaction: The student has already built part of the solution and clearly identifies the remaining gap. This gives the mentor a visible Point A (the age input), Point B (the partially completed branch), and Point C (the missing Adult result) so it can scaffold the connection without immediately writing the missing code.

What happens next? When you paste this partial implementation and your question immediately after the Mentor Prompt, you receive feedback like the example shown below.

🧩 Elite Mentor Stage 3 | Topic #23 | Complete | Python Core & Scripting | πŸ“Š Level: Intermediate

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

Welcome! You have laid down an excellent foundation, now let us place the final puzzle piece. It is entirely normal to reach this stage and second-guess the blueprint. The fact that you are pausing to ask “should this be an elif or an else?” means you are thinking like a true architect of logic.

Let’s look at the flow of your materials and figure out exactly what the roof should look like.

The Data Gap Analysis:

  • Point A (The Input): An integer representing a user’s age. For example, 25.
  • Point B (Current State): Your code successfully routes ages < 13 to “Child” and ages < 20 to “Teen”. But when the age is 25, it fails both tests, falls completely through your conditional structure, and returns the default starting value: "Unknown".
  • Point C (Required Output): The data needs to be captured and transformed into "Adult" before the function returns.

Structural Hint:

Think of a conditional chain like sorting mail. if is your first specific sorting bin. elif is your second specific sorting bin. Now, you have a pile of mail remaining. If you need to sort some of that remaining mail into a specific “Adult” bin and the rest into a “Senior” bin, you need another specific label. But, if you want every single piece of remaining mail to go into the “Adult” bin, you don’t need to read the labels anymoreβ€”you just need a giant catch-all bucket at the end of the line.

Code Observations:

  • You have smartly initialized category = "Unknown" on line 2. This is a great safety net so your function always has something to return.
  • Your routing logic relies on the cascading nature of if/elif. Because < 13 catches everything up to 12, your < 20 check safely assumes the age is already 13 or higher. This is very clean logic!

Socratic Question:

Since we want everyone who bypassed the first two checks (meaning they are mathematically guaranteed to be 20 or older) to be categorized as an “Adult”, do we really need to ask Python to evaluate another mathematical condition like age >= 20, or can we just use the structural keyword that means “for absolutely everything else”?

Next Step:

Check your Python documentation or notes on the difference between elif (which requires a specific condition to evaluate to True) and else (which requires no condition and acts as the ultimate fallback). Decide which one fits your blueprint best, and add those two lines to the end of your chain!

πŸ›‘ THE EXPLANATION GATE πŸ›‘ Before scrolling down to see the Master Code, articulate HOW the data transforms from State B to State C. Copy-pasting without understanding the flow builds Epistemic Debt.

Phase 2: Full Solution

You built a fantastic foundation here. Your use of a cascading threshold (< 13, then < 20) proves you understand how the decision tree evaluates from top to bottom. Here is the completed structure:

Python
def categorize_user(age):
    category = "Unknown"

    if age < 13:
        category = "Child"
    elif age < 20:
        category = "Teen"
    else:
        # ADDED: The catch-all bucket for anything 20 or greater
        category = "Adult"

    return category

users = [10, 15, 25, 18]

for u in users:
    print(f"Age {u} is categorized as: {categorize_user(u)}")

The Clean Connection:

Using else is the most idiomatic and efficient way to close this logic gap. While you could have written elif age >= 20:, it is redundant. By the time the Python interpreter bypasses the < 20 check, the laws of mathematics dictate the age must be 20 or higher. Using else explicitly tells other programmers reading your code: “This is the final fallback state for all remaining valid inputs.”

Positive Reinforcement:

I want to explicitly praise your setup on line 2: category = "Unknown". This is called defining a default state, and it prevents a very common UnboundLocalError if the conditional chain somehow failed to assign a value. Great architectural habit!

⚠️ Common Mistakes:

  • Over-engineering: Writing elif age >= 20: instead of else:. While it works, it forces the computer to do unnecessary math and clutters the code.
  • Misunderstanding else syntax: Trying to give else a condition (e.g., else age >= 20:). else takes no arguments; it just takes a colon :.

πŸ‹οΈ Mini-Challenges:

  1. The Senior Addition: The requirements changed! Anyone 65 or older must now be categorized as “Senior”. How will you adjust your chain using a new elif while keeping else as the fallback for Adults?
  2. Negative Ages: What happens right now if you pass -5 into your function? Modify the logic so that any age less than 0 returns "Invalid Age". Where should this check be placed in the chain?

⚑ Coding5s Mentor System β€” Eliminating Epistemic Debt & Connecting the Flow

Scroll to Top