Year 9Technology 60 min
We are learning to
- We are learning to write a Python program that takes input, makes decisions and repeats steps.
- We are learning to test a program with planned inputs, including boundary values.
Success criteria: I can…
- I can use input() and int() to get a number from the user and store it in a variable.
- I can use if, elif and else to choose a price, with correct colons and indentation.
- I can use a for loop to repeat steps and keep a running total.
- I can test my program with boundary ages and explain what each test checks.
Key competenciesThinkingManaging self
Lesson sequence
60 min total- 1
The ticket rules
Starter 0–6 minTeacher- Display the movie night price list: under 5 free; 5 to 12 $8; 13 to 64 $15; 65 and over $10.
- Ask: How much for a 12-year-old? ($8)
- Ask: A 13-year-old? ($15)
- Ask: A family of three aged 4, 12 and 40? ($0 + $8 + $15 = $23)
- Say: “A computer has to make exactly the same decisions. Today you will write a program that does it.”
Students- Work out the prices on mini whiteboards.
- Notice which ages are on the edges of a price band.
Price list on the screen Mini whiteboards - 2
Stage 1: input and output
Main 6–16 minTeacher- Model in the editor, typing live
- age = int(input("How old are you? "))
- print("You are " + str(age) + " years old.")
- Run it and type 12. Output: You are 12 years old.
- Say: “input() always gives back text. int() turns it into a number. str() turns the number back into text so we can join it to other text with +.”
- Ask: What happens if I leave out int() and later compare age < 13? (an error, because Python can't compare text with a number)
- Students type and run Stage 1, then add a first line: print("Welcome to Movie Night!")
- Tip: When students get an error, have them read the last line of the message aloud before asking for help.
Students- Type Stage 1, run it with two different ages and check the output.
- Add the welcome line.
Devices with IDLE, Programiz or Trinket Stage 1 code on the screen - 3
Stage 2: choose the price
Main 16–30 minTeacher- Model, explaining each line
- if age < 5:
- price = 0
- elif age < 13:
- price = 8
- elif age >= 65:
- price = 10
- else:
- price = 15
- print("Ticket price: $" + str(price))
- Say: “Python checks from the top and runs only the first branch that is true. That's why elif age < 13 doesn't need to say 'and age is 5 or more'.”
- Point to the colon at the end of each if, elif and else line and the four-space indent.
- Students add Stage 2 under their Stage 1 code, then test with the boundary ages and record results in a test table:
- Questions
- 1.Age 4 (expected $0)
- 2.Age 5 (expected $8)
- 3.Age 12 (expected $8)
- 4.Age 13 (expected $15)
- 5.Age 64 (expected $15)
- 6.Age 65 (expected $10)
- Ask: Why test 12 and 13, not just 10 and 30? (the price changes between 12 and 13, so that's where a mistake like <= instead of < would show up)
Students- Add the if/elif/else block and run it six times with the test ages.
- Fill in the test table: input, expected output, actual output, pass or fail.
Stage 2 code on the screen Test table, one per student - 4
Stage 3: a loop for the whole group
Main 30–48 minTeacher- Say: “Families buy several tickets. We'll ask how many, then repeat the price decision for each person and add it up.”
- Show the full program
- print("Welcome to Movie Night!")
- people = int(input("How many tickets? "))
- total = 0
- for i in range(people):
- age = int(input("Age of person " + str(i + 1) + ": "))
- if age < 5:
- price = 0
- elif age < 13:
- price = 8
- elif age >= 65:
- price = 10
- else:
- price = 15
- print("Ticket price: $" + str(price))
- total = total + price
- print("Total to pay: $" + str(total))
- Say: “Everything indented under for repeats. The last print is not indented, so it runs once after the loop.”
- Ask: Why does total = 0 go before the loop, not inside it? (inside, it would reset to 0 for every person and lose the earlier prices)
- Ask: Why str(i + 1)? (range starts at 0, so i + 1 numbers people from 1)
- Students edit their code into the full program. Test: 3 tickets, ages 4, 12, 40. Expected: $0, $8, $15, Total to pay: $23.
- Second test: 3 tickets, ages 5, 13, 65. Expected: $8, $15, $10, Total to pay: $33.
- Tip: The most common bug is indenting total = total + price one level too little, so only the last person is added. Ask students to trace it with the first test.
Students- Build the full program, indenting the loop body.
- Run both tests and check the totals.
- If finished, add a line after the loop that prints the number of tickets sold.
Full program on the screen - 5
Exit check
Plenary 48–60 minTeacher- Students answer on an exit slip without running code:
- Questions
- 1.What does the program print as the total for 2 tickets with ages 70 and 8? ($10 + $8 = $18, so Total to pay: $18)
- 2.A student wrote elif age <= 13: instead of elif age < 13:. Which test age would show the bug, and what would it print? (age 13 would print $8 instead of $15)
- 3.Why is print("Total to pay: $" + str(total)) not indented? (it must run once, after the loop finishes, not once for every person)
- 4.Name the three programming ideas you used today and the line where each starts. (input: people = int(input(...)); selection: if age < 5:; loop: for i in range(people):)
- Take answers to question 2 aloud and link it back to why we test boundaries. Students save their file as movie_night.py.
Students- Answer the four questions alone.
- Save their program.
Exit slips
Key vocabulary
variable
A named place that stores a value, such as age = 12, which the program can use and change.
input()
A Python function that shows a message, waits for the user to type and gives back what they typed as text.
int()
Turns text such as "12" into a whole number 12, so the program can compare it or do maths with it.
selection
Choosing which code to run with if, elif and else, depending on whether a condition is true.
loop
Code that repeats. A for loop repeats a set number of times.
boundary value
A test value right at the edge where the program's behaviour should change, such as age 13 when the price changes at 13.
Differentiation
Support
- Give a printed copy of each stage with the indentation shown as dots (....) so students can see exactly where the four spaces go.
- Give Stage 3 with the loop line and total lines already written, so students paste their working Stage 2 code inside the loop and indent it.
- Pair students for testing: one reads the expected output from the test table while the other runs the program.
Extension
- Add input checking: if someone types an age below 0 or above 120, print "Please check that age" and charge nothing for that ticket.
- Add a family deal: if 4 or more tickets are bought, take $5 off the total. Write the two extra test cases that prove the deal works at exactly 3 and 4 tickets.
- Rewrite the loop as a while loop that keeps asking for ages until the user types 0, and explain when a while loop is a better choice than a for loop.
Accessibility
- Increase the editor font size and keep the full program on the screen throughout so students can compare line by line.
- Offer a printed error-message guide showing the three most common errors today (missing colon, wrong indentation, ValueError from typing a word into int()) and what each means.
- Pre-teach input, output, variable, condition and loop with a short real-life example of each for English language learners.
Assessment
- Check each student's Stage 1 runs and prints the age before moving on.
- Test table: a secure table shows all six boundary ages with expected and actual outputs and any failures fixed.
- Full program: both group tests give $23 and $33.
- Exit question 2 shows whether students understand boundary testing; question 3 shows whether they understand indentation and the loop body.
Resources
- Devices with Python IDLE or a free online editor (Programiz or Trinket)
- Price list, stage code and full program on the screen
- Test table, one per student
- Exit slips