A program is a precise set of instructions, and good programmers plan for their user, test carefully and improve their code until it works for the person who will use it.
We are learning to
- We are learning to write precise algorithms and turn them into Python code.
- We are learning to use variables, input, data types, selection (if, elif, else) and loops in Python.
- We are learning to store and use data in lists.
- We are learning to test programs with expected, boundary and invalid cases and to debug errors.
- We are learning to design a program that meets the needs of a real user, and improve it from feedback.
Success criteria: I can…
- I can write an algorithm in pseudocode with a sequence, a decision and a loop.
- I can use input, variables and int() correctly, and explain why input() always gives a string.
- I can use if, elif and else with comparison operators to make decisions.
- I can use a for loop over a list and a while loop that stops at the right time.
- I can write and carry out a test plan and fix the errors I find.
- I can build a working quiz that meets my user's needs and explain the choices I made.
Week by week
20 lessons · 5 assessment points
- 1
Week 1
- DiagnosticLesson 1 coding starting point: students answer five questions in their workbook: have you coded before, and in what? What is an algorithm? Put six steps for brushing your teeth in order. What does a computer do if an instruction is unclear? Rate your confidence 1 to 5. The teacher uses this to set up pairs for Weeks 1 to 5 and to identify students ready for extension tasks.
Lesson 1What is an algorithm?
Find out what students know and write precise instructions without a computer.
- Diagnostic (10 minutes): the coding starting point in workbooks.
- Unplugged opener (15 minutes): students write instructions for drawing a simple picture (a house made of shapes). A partner follows them exactly, without looking at the picture. Compare the drawings and discuss what went wrong.
- Teach (12 minutes): an algorithm is a precise, ordered set of steps to solve a problem. Three building blocks: sequence (steps in order), selection (making a decision) and iteration (repeating). Find each one in the instructions for making toast.
- Exit (13 minutes): students write a short algorithm for a game of rock, paper, scissors and label a sequence, a decision and a repeat.
Lesson 2First lines of Python
Open the editor, use print, and read and fix error messages.
- Set-up (10 minutes): open the editor, make a folder for the unit and save a file called lesson02_print.py.
- First program (15 minutes): students type print('Kia ora, world!') and run it, then print three lines about themselves (a favourite food, a sport, a place). Show that text in quotes is a string.
- Spot the bug (15 minutes): students run four broken lines one at a time, read each error message and fix it: print('Hello) (missing quote), Print('Hi') (capital P), print('Hi' (missing bracket), print(Hello) (missing quotes, Python looks for a variable called Hello).
- Exit (10 minutes): students write in their workbook the meaning of SyntaxError and NameError in their own words.
- 2
Week 2
Lesson 3Variables and input
Store information in variables and get information from the user with input.
- Box opener (7 minutes): label three boxes 'name', 'town' and 'score' and put a card in each. Explain that a variable is a labelled box that holds a value that can change.
- Teach (13 minutes): name = input('What is your name? ') then print('Hello ' + name). Rules for variable names: no spaces, do not start with a number, use clear names like first_name, not x.
- Practice (20 minutes): students write a 'getting to know you' program that asks three questions and prints a sentence using all the answers, for example print(name + ' lives in ' + town + ' and likes ' + food + '.').
- Exit (10 minutes): students swap programs with a partner, run each other's and suggest one improvement to the questions.
Lesson 4Numbers and data types
Use strings, integers and floats, convert input with int() and do calculations.
- Puzzle opener (8 minutes): show age = input('How old are you? ') then print(age + 1). Students predict the result, then run it: a TypeError, because input() always gives a string and Python cannot add a string and a number.
- Teach (12 minutes): data types: string (text), integer (whole number), float (decimal). Convert with int() and float(), and back to text with str(). Operators: +, -, *, / (always gives a float, so 7 / 2 is 3.5) and // (whole number division, so 7 // 2 is 3).
- Practice (20 minutes): students write a program that asks for an age and prints the age next year, then a pocket money calculator that asks for weekly pocket money and prints how much is saved in 10 weeks.
- Exit (10 minutes): students write what type each value is: 'hello' (string), 42 (integer), 3.14 (float), '42' (string).
- 3
Week 3
- FormativeLesson 6 selection check: students predict the output of four short if, elif and else programs, then write a program that asks for a test score out of 100 and prints 'Excellent' for 80 or more, 'Good' for 50 to 79 and 'Keep practising' below 50. The teacher checks the boundaries 50 and 80 give the right message.
Lesson 5Making decisions with if and else
Use if and else with comparison operators to make decisions.
- Unplugged opener (8 minutes): stand up if you are wearing black shoes, otherwise sit down. Write the rule as 'if ... else ...'.
- Teach (12 minutes): comparison operators ==, !=, <, >, <= and >=, the colon at the end of the if line, and indentation (four spaces) to show which lines belong to the if. Example: if age >= 13: print('You can join the club') else: print('Sorry, the club is for 13 and over'), written on separate lines with indents.
- Practice (20 minutes): students write a password checker (if the password equals a stored one, print 'Access granted', otherwise 'Access denied') and an even or odd checker using number % 2 == 0.
- Exit (10 minutes): students explain the difference between = (stores a value) and == (compares two values).
Lesson 6More choices with elif
Use elif for more than two choices, and lower() and strip() to tidy text answers.
- Opener (7 minutes): run a program that asks 'What is the capital of New Zealand?' and checks if answer == 'Wellington'. Type 'wellington' and ' Wellington'. Why does it say wrong?
- Teach (13 minutes): answer.strip().lower() removes spaces at the start and end and changes to lower case, so compare with 'wellington'. Then elif for more than two choices, checked in order from the top.
- Selection check (20 minutes): the formative selection check, including the score message program.
- Exit (10 minutes): students test their score program with 49, 50, 79 and 80 and record the output.
- 4
Week 4
- FormativeLesson 8 loop trace: students trace three loops on a trace table before running them. Example: total = 0, then for n in range(1, 5): total = total + n, then print(total) prints 10, because range(1, 5) gives 1, 2, 3 and 4. The teacher reteaches range with anyone who includes 5.
Lesson 7A two-question quiz and testing
Build a two-question quiz with a score, and learn expected, boundary and invalid tests.
- Build (15 minutes): students write a quiz with two questions, each with its own if and else, adding 1 to a score variable (score = score + 1) for each correct answer, and printing 'You scored 2 out of 2' style feedback with str(score).
- Teach (12 minutes): a test plan lists each test, the input, the expected result and the actual result. Expected tests use normal answers; boundary tests use values at the edge (49 and 50 in a score rule); invalid tests use wrong types or blank input (pressing Enter, typing 'six' when a number is expected).
- Test (15 minutes): pairs write a test plan of four tests for their two-question quiz and run it, recording results.
- Exit (8 minutes): students note one bug they found and how they fixed it, or one test that would break their program.
Lesson 8Loops: for and while
Repeat code with for loops and range, and with while loops that run until a condition changes.
- Opener (7 minutes): ask students to print 'Kia kaha!' 100 times. Is there a quicker way than typing it 100 times?
- Teach (13 minutes): for i in range(5): repeats five times, with i taking the values 0, 1, 2, 3, 4; range(1, 5) gives 1, 2, 3, 4. A while loop repeats while a condition is true: play = 'yes', then while play == 'yes': ... play = input('Play again? ').strip().lower(). Warn about infinite loops and how to stop one (Ctrl+C or the editor's stop button).
- Loop trace (18 minutes): the formative loop trace on three programs.
- Practice (12 minutes): students write a times table program that asks for a number and prints its table from 1 to 10 with a for loop, and a while loop that keeps asking for the password until it is right.
- 5
Week 5
Lesson 9Lists
Store several values in a list and loop through it.
- Opener (7 minutes): a shopping list on the board. How could a program store ten items without ten variables?
- Teach (13 minutes): planets = ['Mercury', 'Venus', 'Earth'], indexes start at 0, so planets[0] is 'Mercury'; len(planets) is 3; planets.append('Mars') adds to the end. Loop with for planet in planets: print(planet), or for i in range(len(planets)) to use the index.
- Practice (20 minutes): students make a list of five favourite songs or foods, print each with a number in front (1. pizza), and ask the user to add one more.
- Quiz from lists (10 minutes): the teacher shows how a quiz can use two lists, questions = ['What is 6 x 7?', 'What is the capital of New Zealand?'] and answers = ['42', 'wellington'], and a loop with i to ask questions[i] and check answers[i]. Students copy and run it.
Lesson 10Random numbers and a guessing game
Use the random module and a while loop to build a number guessing game.
- Plan (15 minutes): use the pseudocode part of the library lesson "Plan Before You Code: Pseudocode for a Guessing Game" to plan a higher-or-lower game.
- Teach (8 minutes): import random at the top, then secret = random.randint(1, 20) gives a whole number from 1 to 20, including both.
- Build (20 minutes): students turn the pseudocode into Python: a while loop that runs until the guess equals the secret, with 'Too high' and 'Too low' hints and a guess counter. Students ready for more add a limit of five guesses.
- Exit (7 minutes): students write which three building blocks (sequence, selection, iteration) appear in their game and where.
- 6
Week 6
- FormativeLesson 12 plan check: students hand in their user needs summary, pseudocode or flowchart for the quiz, and a test plan with at least six tests (expected, boundary and invalid). The teacher checks the plan meets the project requirements and that each test has an expected result, and returns feedback before building starts.
Lesson 11Who is the quiz for?
Choose a real user for the quiz and find out what they need.
- Launch (10 minutes): introduce the project, the requirements and the rubric. Show a finished example quiz and play it.
- Choose a user (12 minutes): students choose a real user they can reach (a younger sibling revising times tables, a Year 7 class learning about planets, a family member learning road rules, a friend learning te reo Māori words) and a topic.
- User questions (18 minutes): students write five questions to ask their user (what they want to practise, how hard it should be, how they like feedback, how long they will spend), and ask them in person or by message before the next lesson. Students who cannot reach their user interview a classmate in role.
- Exit (10 minutes): students write a one-sentence purpose: 'My quiz helps ... practise ... '.
Lesson 12Planning the quiz and the tests
Write a user needs summary, plan the quiz in pseudocode and write a test plan.
- User needs (10 minutes): students summarise what their user said into three to five needs.
- Questions (10 minutes): students write at least five quiz questions with answers, checking each fact against a reliable source.
- Pseudocode (15 minutes): students plan the program in pseudocode or a flowchart: set score to 0, loop through the questions, ask, tidy the answer, check it, give feedback, show the final score and message, ask to play again.
- Test plan (15 minutes): students write at least six tests: correct answers, wrong answers, answers with capitals and spaces, a blank answer, and the score boundaries for each final message. Hand in for the formative plan check.
- 7
Week 7
Lesson 13Building version 1
Code the quiz's lists, loop, answer check and score.
- Feedback (8 minutes): students read the teacher's feedback on their plan and fix anything needed.
- Build (35 minutes): students code version 1: the questions and answers lists, a for loop with an index, reply = input(questions[i] + ' ').strip().lower(), an if and else to check against answers[i] and add to the score, and a final print of the score out of len(questions). Remind students that the answers in the list must be stored in lower case.
- Save (7 minutes): save as quiz_v1.py and run tests 1 to 3 from the test plan.
Lesson 14Feedback and final messages
Add helpful feedback for each answer and a final message based on the score.
- Opener (8 minutes): compare two feedback messages: 'Wrong.' and 'Not quite, the answer is 42. Six sevens are 42.' Which would your user prefer?
- Build (30 minutes): students add feedback that gives the correct answer when the user is wrong, and a final message using if, elif and else on the score (for example, all correct: 'Ka pai, a perfect score!'; at least half: 'Good work, try again to beat it'; otherwise: 'Keep practising, you are getting there'). The messages suit their user's age and needs.
- Test (12 minutes): run the score boundary tests from the test plan and save as quiz_v2.py.
- 8
Week 8
Lesson 15Play again and handling odd input
Wrap the quiz in a play again loop and handle blank or unexpected answers.
- Opener (7 minutes): run a quiz and press Enter without typing. What happens? Is that what the user would want?
- Teach (10 minutes): put the quiz inside while play == 'yes': and reset score = 0 at the start of each round. To handle a blank answer, use a while loop that asks again: while reply == '': reply = input('Please type an answer: ').strip().lower().
- Build (25 minutes): students add the play again loop and the blank answer check, then run the invalid tests from their test plan.
- Exit (8 minutes): students update the actual results column in their test plan.
Lesson 16User testing
Test the quiz with someone in the user's role and record their feedback.
- Prepare (8 minutes): students write three questions to ask their tester (Were the questions clear? Was it the right difficulty? What would make it better?).
- User test (25 minutes): in pairs, each student watches a partner play their quiz in the role of the user, without helping, and notes where the partner hesitated or got confused. Students whose real user is available can test with them at home and bring the notes.
- Plan changes (12 minutes): students list the changes the feedback suggests and choose the two most important for their user.
- Exit (5 minutes): students write one thing they noticed about their quiz that they had not seen while coding.
- 9
Week 9
Lesson 17Improving the quiz
Make improvements from user feedback and make the code readable.
- Teach (10 minutes): readable code uses clear variable names, comments starting with # to explain each section, and blank lines between sections. Optional improvements: shuffle the order of questions (keep questions and answers together by putting them in pairs in one list, then use random.shuffle), accept more than one correct answer with or, or add a percentage score with round(score / len(questions) * 100).
- Improve (32 minutes): students make their two chosen changes, add comments, and save as quiz_v3.py.
- Exit (8 minutes): a partner reads the code without running it and explains what one section does. If they cannot, the comments need work.
Lesson 18Final testing
Run the full test plan on the finished quiz and fix remaining bugs.
- Common bugs (8 minutes): the teacher shows three common bugs in quiz programs (the score not reset when playing again, an answer stored with a capital letter so it never matches, the final message using > when it should be >=). Students check their own code for each.
- Final test (30 minutes): students rerun every test in their test plan, fill in the actual results and note each fix.
- Peer check (12 minutes): a partner plays the quiz trying to break it, and reports anything that goes wrong.
- 10
Week 10
- SummativeQuiz program and evaluation (Lessons 11 to 20): students hand in their working quiz program, their completed test plan with results and fixes, and a short evaluation (about 200 words) of how well the quiz meets their user's needs, using feedback from the user test in Lesson 16. Marked with the project rubric: the program runs without errors; it meets all requirements (five or more questions in lists, a loop, a score, feedback, answers that ignore capitals and spaces, a final message based on the score, a play again option); the code is readable (clear variable names and comments); testing is thorough; and the evaluation links decisions to the user.
Lesson 19Demonstration and hand-in
Demonstrate the quiz and hand in the program and test plan.
- Demonstrations (35 minutes): in groups of four, each student demonstrates their quiz for two minutes, explains who it is for and one decision they made for their user, and shows one section of code.
- Hand in (10 minutes): students hand in quiz_v3.py (or their final version) and the completed test plan.
- Exit (5 minutes): students share their quiz with their user, if the school's approach allows.
Lesson 20Evaluation and next steps
Write an evaluation of how well the quiz meets the user's needs and reflect on learning.
- Model (8 minutes): show a sentence frame: 'My user needed ... so I ... The test showed ... Next time I would ...'.
- Evaluation (30 minutes): students write their summative evaluation of about 200 words, linking each decision to the user's needs and the feedback from user testing.
- Reflection (12 minutes): students compare their Lesson 1 confidence rating with now, and list the Python features they can now use.
Cross-curricular links
- Mathematics and Statistics: arithmetic operators, integer and decimal results, and comparing values with greater than and less than.
- English: writing clear questions and feedback messages for a particular reader.
- The user's subject: the quiz content comes from another learning area (for example science facts or road rules), so the facts must be checked against a reliable source.
Te ao Māori connections
- In Lesson 11, if a student chooses a user who is learning te reo Māori, discuss how to handle macrons in answers (for example, accepting both 'kāinga' and 'kainga' with an or condition, and explaining why it matters to show the macron in the feedback). Check the quiz's te reo content with your school's kaiako Māori before it is given to the user.
Resources
- Computers with a Python 3 editor such as Thonny or IDLE, or a school-approved browser editor
- Coding starting point questions and workbooks, paper or digital (Lesson 1)
- Simple shape pictures for the unplugged drawing task (Lesson 1)
- Spot the bug lines and error message chart (Lesson 2)
- Three labelled boxes and cards for the variables opener (Lesson 3)
- Data type and operator reference sheet (Lesson 4)
- Selection check sheet (Lesson 6)
- Test plan template (Lessons 7, 12 and 15 to 18)
- Loop trace tables (Lesson 8)
- Library lesson "Plan Before You Code: Pseudocode for a Guessing Game" (Lesson 10)
- Library worksheet "Python Basics: Variables, Decisions and Loops" for revision or homework (Weeks 2 to 5)
- Example finished quiz program, user question template and project rubric (Lessons 11 and 12)
- Evaluation sentence frames (Lesson 20)