Stage 2

🔹 Topic #33 | Stage 2 | Python | 📊 Level: Intermediate | 🌐 Coding5s.com
Concept: Dictionary & Set Comprehensions (Syntax & filtering)

Role Reversal (The Frustrated Junior): Stage 2 flips the traditional AI learning model. Instead of the AI acting as the omniscient teacher, the prompt forces it to adopt the persona of a frustrated Junior Developer. This drastically lowers the student’s imposter syndrome and places them in the active, critical role of a Senior code reviewer.

Ugh, I don’t understand why my code never works on the first try, I’ve spent hours trying to get these comprehensions to do what they are supposed to do but the data comes out wrong.
Challenge 1 (Score 3):
Objective: Create a dictionary with product names and their prices applying a 20% discount, excluding those of 50 or less.
Expected Output:
Plaintext
{'laptop': 800.0, 'monitor': 160.0}

Gamification & Logical Bugs: Every challenge includes a point-based ‘Score’ and clear ‘Expected Output’ (Acceptance Criteria). Crucially, the AI is instructed to introduce logical bugs (like multiplying by 1.20 instead of 0.80, or using the wrong comparison operator) rather than simple syntax errors. This forces the student to trace the execution flow and builds real-world debugging muscle.

Broken Code:
Python
def calculate_discounts():
    data = [("laptop", "1000"), ("mouse", "20"), ("monitor", "200")]
    discounts = {
        name: float(price) * 1.20
        for name, price in data
        if float(price) < 50
    }
    for product in discounts:
        print(product)
    print(discounts)

calculate_discounts()
Scroll to Top