Computer ScienceComputingMiddle schoolKey Stage 3
How to teach if-then statements
If-then statements let a program choose what to do. In Python, if, elif and else run one block of code depending on which condition is true. This page explains how they work, with a free activity where students code a choose-your-path story and Sparky tests the paths they skipped.
Jemel Fanfan | Founding Member at Flint

"Flint was mostly employed by students as an easy-to-reach one-on-one tutor. The fast, non-judgmental comments helped them swiftly improve their writing and coding tasks."
Jason Graham, Social Studies/Inquiry Teacher at Jakarta Intercultural SchoolWhy this matters
A student writes three branches for her story, runs the program once with the answer she expects, and calls it done. The bugs sit in the branches she never ran: a capital letter, an extra space, an answer the story doesn't cover. Her program looks finished, and the teacher has to wait until every program is graded to find out which ones break.
If-then statements in Python
An if-then statement runs a block of code only when a condition is true. In Python, an if line checks the first condition, each elif line (short for "else if") checks another one in order, and an else line runs when none of them matched (Python tutorial). Python runs exactly one branch: the first one whose condition is true. When nothing matches and there is no else, none of the branches run (Python language reference). A comparison such as choice == "left" matches only that exact text, so "Left" and "left " fall through to another branch until the code changes them with the string methods lower() and strip(). Geometry classes use the same words for conditional statements ("if p, then q"), and this page is about if-then statements in code.
In the Flint activity, each student codes a short choose-your-path story with if, elif and else, runs it in Flint's code editor and sends it to Sparky. A worksheet shows one branch to trace, and Sparky asks what each student's own program prints for answers they never tried.
Sparky gets Nadia to test the answers she skipped and fix them herself
Nadia ends up testing answers she never tried and making her story handle any capitalization with .lower(). Everyone in the class gets the same activity, and Sparky's replies depend on each student's own code and answers.
Nadia
Sparky

Nadia

Sparky
choice = "Upstairs" with a capital U?Nadia
with Upstairs it only printed the first line, the ghost girl part disappeared. so i fixed it, i added another elif for Upstairs and now it works
Sparky
Nadia
i looked it up, .lower() makes it all lowercase. i took out the extra elif and tried UPSTAIRS and it works
Understanding check
Nadia
ok i added a second question inside upstairs. i tried open and it finds the diary!Tested one answer, then fixed capitals herself and added a nested if
Nadia is an example student, and Sparky's replies are shortened.
What Flint did for Nadia
- When Nadia tested only "upstairs", Sparky asked what her program prints for "Upstairs" with a capital U.
- When she patched it with a second elif, Sparky sent her back to her choice variable without giving the fix.
- Once .lower() fixed her capitals, Sparky asked for a harder version with a second question nested inside one path.
A teacher can't do this by hand for 30 students, and Sparky does it in every student's chat.
The activity page shows whose stories skip a path
While the class works, Needs attention shows the teacher which student is stuck and on which message. After three or more students submit, activity analytics lists what the class did well, where students went wrong, and a follow-up to practice next.

Example activity page
After a class codes their choose-your-path stories
The school and students are made up for this page, and clicking a student opens their chat and the story they coded.
Set up the activity for free
The choose-your-path activity is in Flint's public library, with the Path Tracer, Sparky's guidelines and the greeting already written. Select Use activity to copy it into a free Flint account and assign it to a class. Students open the code editor with the Write code button and pick Python from its language menu, and since the editor can't read typed answers, they store the reader's answer in a variable such as choice = "hide" instead of using input().
For a project where each student picks the program to write, see how to run coding projects in middle school. For more computer science activities, see Flint for computer science.
Other use cases
See all use cases →English Language ArtsEnglishMiddle schoolKey Stage 3

How to teach independent and dependent clauses
Independent and dependent clauses explained, with the comma rule, and a free Flint activity: students build sentences from clause tiles about their own weekend, and a clause that can't stand alone gets a question back instead of the answer.
MathematicsMathsHigh schoolKey Stages 4 and 5

How to teach inequalities
How to teach inequalities so students can write one from a word problem: one student compares two gym plans in a spreadsheet Sparky builds, finds where the cheaper plan switches, and writes the inequality that proves it, with a free Algebra 1 activity.
English Language ArtsEnglishElementaryPrimary

How to teach inference
What making inferences means and how students back an inference with clues from the text, with a free Flint activity: each student photographs a page from their own book, and an answer with no clue sends the student back to one sentence on that page.
