Popcorn Hack 1: After-School Homework Plan

  1. Prediction for the original values (is_weekday = True, homework_finished = False): “Finish homework”
  2. Branches followed: the outer if runs because it’s a weekday, then the inner else runs because homework isn’t finished.
  3. The other two outcomes: is_weekday = True, homework_finished = True gives “Free time,” and is_weekday = False gives “Weekend plan” (the homework value doesn’t matter there, because the inner check is skipped).

Code Runner Challenge

Popcorn Hack 1 - Test the after-school homework plan

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 1 - Test the after-school homework plan

def after_school_plan(is_weekday, homework_finished):
    # Outer decision: the inner homework check only happens on a weekday.
    if is_weekday:
        if homework_finished:
            print("Free time")
        else:
            print("Finish homework")
    else:
        print("Weekend plan")

# Original values: outer branch = is_weekday is True (the if), inner branch = homework_finished is False (the else)
print("weekday, not finished ->", end=" ")
after_school_plan(True, False)

# The other two outcomes
print("weekday, finished     ->", end=" ")
after_school_plan(True, True)
print("weekend               ->", end=" ")
after_school_plan(False, False)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Actual output:

Code Runner Challenge

Popcorn Hack 2 - Repair the student account check

View IPYNB Source
weekday, not finished -> Finish homework
weekday, finished     -> Free time
weekend               -> Weekend plan
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 2: Repair the Student Account Check

Why the original wasn’t nested: the permission if started at the same indentation level as if logged_in:, so it was a separate, independent decision. It ran for every student, logged in or not, instead of only after login.

The fix: indent the permission check inside the logged-in branch, and add an outer else that prints “Log in first.”

Code Runner Challenge

Popcorn Hack 3 - Test the lunch and sports-practice plan

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 2 - Repair the student account check

def open_page(logged_in, has_permission):
    if logged_in:
        print("Account found")
        # Indented one level deeper, so the permission check now belongs to the logged-in branch.
        # It only runs after the student has logged in.
        if has_permission:
            print("Page opened")
        else:
            print("Permission needed")
    else:
        # Outer else: a logged-out student never reaches the permission check.
        print("Log in first")

print("Test 1: logged in, has permission")
open_page(True, True)
print("Test 2: logged in, no permission")
open_page(True, False)
print("Test 3: logged out")
open_page(False, False)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Actual output:

Code Runner Challenge

Homework Hack - Build a high school daily routine dashboard

View IPYNB Source
Test 1: logged in, has permission
Account found
Page opened
Test 2: logged in, no permission
Account found
Permission needed
Test 3: logged out
Log in first
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

All three messages print: “Page opened,” “Permission needed,” and “Log in first.”

Popcorn Hack 3: Lunch and Sports Practice

# CODE_RUNNER: Popcorn Hack 3 - Test the lunch and sports-practice plan

def lunch_plan(lunch_packed, practice_after_school):
    # Outer: lunch is decided first. Inner: practice changes what to do about food in each path.
    if lunch_packed:
        if practice_after_school:
            print("Eat your packed lunch and bring an extra snack for practice.")
        else:
            print("Eat your packed lunch. No extra snack needed today.")
    else:
        if practice_after_school:
            print("Buy lunch at school and buy an extra snack for practice.")
        else:
            print("Buy lunch at school. No extra snack needed today.")

lunch_plan(True, True)
lunch_plan(True, False)
lunch_plan(False, True)
lunch_plan(False, False)

Actual output:

Eat your packed lunch and bring an extra snack for practice.
Eat your packed lunch. No extra snack needed today.
Buy lunch at school and buy an extra snack for practice.
Buy lunch at school. No extra snack needed today.

All four recommendations print, one for each combination of the two values.

JavaScript:

if (lunchPacked) {
    if (practiceAfterSchool) {
        console.log("Eat your packed lunch and bring an extra snack for practice.");
    } else {
        console.log("Eat your packed lunch. No extra snack needed today.");
    }
} else {
    if (practiceAfterSchool) {
        console.log("Buy lunch at school and buy an extra snack for practice.");
    } else {
        console.log("Buy lunch at school. No extra snack needed today.");
    }
}

College Board pseudocode:

IF (lunchPacked)
{
    IF (practiceAfterSchool)
    {
        DISPLAY("Eat your packed lunch and bring an extra snack for practice.")
    }
    ELSE
    {
        DISPLAY("Eat your packed lunch. No extra snack needed today.")
    }
}
ELSE
{
    IF (practiceAfterSchool)
    {
        DISPLAY("Buy lunch at school and buy an extra snack for practice.")
    }
    ELSE
    {
        DISPLAY("Buy lunch at school. No extra snack needed today.")
    }
}

Execution order: lunch_packed is checked first because it’s the outer condition. It picks which half of the code runs. Only then is practice_after_school checked, inside whichever half was chosen. Python shows this with indentation, while JavaScript and pseudocode show it with braces.

Homework Hack: High School Daily Routine Dashboard

The dashboard uses the starter data plus four student-life values (login, homework, lunch, and practice). It has an outer account if / else and three levels of nested decisions, and it produces 7 different recommendations. It runs the starter student, then a test for every meaningful outcome.

# CODE_RUNNER: Homework Hack - Build a high school daily routine dashboard

student = {
    "logged_in": True,
    "homework_finished": False,
    "lunch_packed": True,
    "practice_today": True
}

def daily_dashboard(student):
    # Outer decision: account access. Nothing about the schedule is shown until the student logs in.
    if student["logged_in"]:
        # Nested decision 1: homework status decides how the after-school time gets used.
        if student["homework_finished"]:
            # Nested decision 2: practice only matters once we know homework is handled.
            if student["practice_today"]:
                # Nested decision 3: the meal plan only matters on a practice day, because practice
                # is what creates the need for extra food before dinner.
                if student["lunch_packed"]:
                    print("Eat your packed lunch, bring a snack to practice, then relax after dinner.")
                else:
                    print("Buy lunch and an extra snack before practice, then relax after dinner.")
            else:
                print("Homework is done and there's no practice: enjoy free time before dinner.")
        else:
            if student["practice_today"]:
                if student["lunch_packed"]:
                    print("Eat your packed lunch, start homework in your free period, go to practice, and finish homework after dinner.")
                else:
                    print("Buy lunch, start homework in your free period, go to practice, and finish homework after dinner.")
            else:
                print("No practice today: start homework right after school so it's done before dinner.")
    else:
        print("Log in first to see your daily plan.")

# The starter data: logged in, homework not finished, lunch packed, practice today
print("Starter student:")
daily_dashboard(student)
print()

# Tests that reach every meaningful outcome. Lunch only changes the result on practice days,
# so it is tested in those paths and left at one value elsewhere.
tests = [
    {"logged_in": False, "homework_finished": True, "lunch_packed": True, "practice_today": True},
    {"logged_in": True, "homework_finished": True, "lunch_packed": True, "practice_today": True},
    {"logged_in": True, "homework_finished": True, "lunch_packed": False, "practice_today": True},
    {"logged_in": True, "homework_finished": True, "lunch_packed": True, "practice_today": False},
    {"logged_in": True, "homework_finished": False, "lunch_packed": True, "practice_today": True},
    {"logged_in": True, "homework_finished": False, "lunch_packed": False, "practice_today": True},
    {"logged_in": True, "homework_finished": False, "lunch_packed": True, "practice_today": False},
]

for number in range(len(tests)):
    test = tests[number]
    print("Test", number + 1, "| logged in:", test["logged_in"], "| homework done:", test["homework_finished"],
          "| lunch packed:", test["lunch_packed"], "| practice:", test["practice_today"])
    daily_dashboard(test)

Actual output:

Starter student:
Eat your packed lunch, start homework in your free period, go to practice, and finish homework after dinner.

Test 1 | logged in: False | homework done: True | lunch packed: True | practice: True
Log in first to see your daily plan.
Test 2 | logged in: True | homework done: True | lunch packed: True | practice: True
Eat your packed lunch, bring a snack to practice, then relax after dinner.
Test 3 | logged in: True | homework done: True | lunch packed: False | practice: True
Buy lunch and an extra snack before practice, then relax after dinner.
Test 4 | logged in: True | homework done: True | lunch packed: True | practice: False
Homework is done and there's no practice: enjoy free time before dinner.
Test 5 | logged in: True | homework done: False | lunch packed: True | practice: True
Eat your packed lunch, start homework in your free period, go to practice, and finish homework after dinner.
Test 6 | logged in: True | homework done: False | lunch packed: False | practice: True
Buy lunch, start homework in your free period, go to practice, and finish homework after dinner.
Test 7 | logged in: True | homework done: False | lunch packed: True | practice: False
No practice today: start homework right after school so it's done before dinner.

Every meaningful outcome is reached: logged out (Test 1), homework done with practice and a packed or bought lunch (Tests 2 and 3), homework done with no practice (Test 4), homework not done with practice and a packed or bought lunch (Tests 5 and 6), and homework not done with no practice (Test 7).

Why the inner checks depend on the outer decisions: The schedule checks are nested inside the login check because a logged-out student shouldn’t see any personal schedule, so there’s no reason to look at homework or practice until login succeeds. Within that, the meal check is nested inside the practice branch because practice is what creates the need for extra food before dinner, so on a day with no practice, the lunch choice doesn’t change the recommendation. If these were separate, un-nested if statements, a logged-out student would still get schedule advice, and every student would get practice-snack advice even on days with no practice.