Learn

Module 01 · Foundations

Python Foundations for AI

Build the programming discipline required for AI development: clean syntax, structured programs, reliable data handling, and a professional Python workflow.

in progress12 hours · Week 1–2

Variables and types / HOOK

Start here: Python that AI projects actually use

1/10

INCIDENT REPORT #301 — E-Commerce Discount Calculator

Expected: Expected total for $100 cart with 20% discount ($80) + 5% tax on discounted amount ($4) is $84.00. Actual: Calculated output is $79.00 — $5 cheaper than it should be!

WHY THIS MATTERS

Forming a testable hypothesis before looking at the fix primes your analytical intuition.

concept_execution.pyPython 3.12
def calculate_final_price(cart_items, discount_code):
    subtotal = 0
    for item in cart_items:
        subtotal += item["price"] * item["quantity"]

    # AI generated this discount logic:
    if discount_code == "SAVE20":
        discount = subtotal * 0.20
    elif discount_code == "SAVE10":
        discount = subtotal * 0.10
    else:
        discount = 0

    # Apply 5% tax
    total = subtotal - discount * 1.05
    return round(total, 2)

# Test run:
cart = [{"price": 100, "quantity": 1}]
print(calculate_final_price(cart, "SAVE20"))