Revise360The course

Python course, alongside the specification

Python Python programming

Thirteen lessons of Python written and run in the browser, from your first printed line through to merge sort and SQL. Every question is marked as it is answered, so progress shows lesson by lesson. Taught in 13 lessons, each with its own 360° room, alongside the unit's PowerPoints, worksheets and lesson plans.

The Arithmetic lesson room.
Python · Lesson 2 Arithmetic

What this topic covers

13 lessons, in teaching order.

Each lesson opens with retrieval from earlier lessons, is taught from its PowerPoint, and is explored in its room, where every station has a short explainer and questions.

  1. Lesson 1: Printing and variables

    Why must a program decide the data type of a value before it can do anything useful with it?

    Pupils learn to

    • know how to print lines of output in the order a task asks for
    • know how to hold a value in a variable or a constant, and how to read one with input()
    • understand why a value that has been typed in must be cast before it can be calculated with

    In the room Printing output · Variables · Reading input · Numbers and text · Casting · Putting it together · Final challenge: name the data type

    Open this room, no sign-in
  2. Lesson 2: Arithmetic

    How do you choose between /, // and % when the answer to a calculation has to come out as a whole number?

    Pupils learn to

    • know which arithmetic operator each kind of calculation needs
    • understand the difference between /, // and % and what each one hands back
    • know how to round a result, and how to draw a random number from a seed

    In the room The four operations · Whole number division · Powers and roots · Rounding · Random numbers · Putting it together · Final challenge: pick the operator

  3. Lesson 3: Selection

    Why does the order the branches are written in change what an if ... elif ... else actually does?

    Pupils learn to

    • know how to write a condition using the comparison operators
    • understand how if, elif and else choose between several outcomes
    • know how to join two conditions together with and, or and not

    In the room Comparing values · if and else · elif · AND, OR and NOT · Decisions inside decisions · Putting it together · Final challenge: true or false

  4. Lesson 4: Count-controlled loops

    How do you decide what to put inside range() so that a loop counts exactly the values you want?

    Pupils learn to

    • know how to write a for loop that repeats a block a set number of times
    • understand how range() decides which values the loop counter takes
    • know how to build a running total inside a loop, and how to put one loop inside another

    In the room Repeating a line · Using the counter · Choosing the range · Running totals · Loops inside loops · Putting it together · Final challenge: how many times?

  5. Lesson 5: Condition-controlled loops

    How do you decide between a for loop and a while loop before you write a single line of code?

    Pupils learn to

    • know how to write a while loop and what makes it stop repeating
    • understand how a validation loop keeps asking until the value typed in is acceptable
    • know how a sentinel value ends a loop when the amount of data is not known in advance

    In the room A loop with a condition · Asking until it is right · Sentinel values · Counting inside a while · Choosing for or while · Putting it together · Final challenge: for or while?

  6. Lesson 6: String handling

    Why are the characters of a string numbered from 0 rather than from 1?

    Pupils learn to

    • know how to find the length of a string and the character at a given position
    • understand how a slice takes part of a string, and why its end position is left out
    • know how to change case, search inside text, and move between a character and its code

    In the room Length and position · Taking part of a string · Upper and lower case · Searching inside text · Character codes · Putting it together · Final challenge: what does it give?

  7. Lesson 7: Lists

    Why is the last item of a list always at index len(list) - 1?

    Pupils learn to

    • know how to create a list and read one item out of it by its index
    • understand how to traverse a list in order to total, count or compare its items
    • know how to add an item onto a list and how to take one out again

    In the room Making a list · Reading an item · Going through a list · Adding and removing · Totals and averages · Putting it together · Final challenge: what does it do?

  8. Lesson 8: Two-dimensional lists

    Which index comes first when a program reads a cell, and why does swapping the two over give a different answer?

    Pupils learn to

    • know how to build a two-dimensional list as a list of lists and fill it from input
    • understand how a row index and a column index together pick out one cell
    • know how to write nested loops that print a grid and total any row or column of it

    In the room A list of lists · Rows and columns · Going through a grid · Totalling a row · Totalling a column · Putting it together · Final challenge: read the grid

  9. Lesson 9: Subprograms

    When should a subprogram return a value rather than print one?

    Pupils learn to

    • know how to define a subprogram with def and how to call it
    • understand how a parameter carries a value into a subprogram and how return carries one back out
    • know how to write a subprogram that uses a variable of its own, and one that changes a shared variable

    In the room Writing a procedure · Parameters · Returning a value · Functions and procedures · Local and global · Putting it together · Final challenge: function or procedure?

  10. Lesson 10: File handling

    Why does the mode a file is opened in matter more than anything else on that line?

    Pupils learn to

    • know how to open a text file, read what is in it and close it again
    • understand what write mode does to a file, and how append mode differs from it
    • know how to split one line of a file into its separate fields and use them

    In the room Reading a whole file · Reading line by line · Writing to a file · Adding to a file · Records in a file · Putting it together · Final challenge: which mode?

  11. Lesson 11: Searching and sorting

    Why is a binary search so much faster than a linear search on a long list, and what does using one cost you?

    Pupils learn to

    • know how to code a linear search and a binary search, and report the position each one finds
    • understand how a bubble sort, an insertion sort and a merge sort each put a list in order
    • know how to count the comparisons an algorithm makes, in order to compare two of them

    In the room Linear search · Binary search · Bubble sort · Insertion sort · Merge sort · Putting it together · Final challenge: which algorithm?

  12. Lesson 12: Validation and authentication

    Why is refusing bad data better than letting a program stop with an error?

    Pupils learn to

    • know how to code a presence check, a type check and a range check
    • understand how a length check and a format check differ, and why the length is tested first
    • know how to write a validation loop, and an authentication check that allows a set number of attempts

    In the room Checking the input · Range checks · Length and format checks · Keeping asking · Authentication · Putting it together · Final challenge: which check?

  13. Lesson 13: SQL queries

    Which clause of a query decides which fields come back, and which clause decides which records?

    Pupils learn to

    • know how SELECT and FROM choose the fields and the table a query reads
    • understand how WHERE decides which records a query hands back
    • know how to join conditions with AND and OR, and how to put results in order with ORDER BY

    In the room SELECT and FROM · WHERE · Comparing values · AND and OR · Sorting results · Putting it together · Final challenge: build the query

Key words

The words to use in an answer.

abs()
A built-in function that returns the absolute value of a number, its size without any minus sign, so abs(-7) gives 7.
Append mode
Opening a file with open(name, "a") so that anything written is added to the end of the file and its existing contents are kept.
append()
A list method that adds one item to the end of a list, making the list one item longer.
Argument
The actual value given to a subprogram when it is called; it is received by the matching parameter in the subprogram's definition.
Arithmetic
Calculations on numbers using operators such as +, -, *, /, // (DIV), % (MOD) and ** (exponent).
chr()
A built-in function that takes a character code (an ASCII or Unicode number) and returns the character it stands for, so chr(65) gives "A".
Column
The values in a two-dimensional array that share the same second index, so grid[0][2], grid[1][2] and so on make up column 2.
Condition
An expression that evaluates to True or False, used to decide which branch of a selection runs or whether a loop repeats again.
Condition-controlled
Iteration that repeats while a condition stays True (or until it becomes True), so the number of repeats is not known in advance; in Python, a while loop.
Count-controlled
Iteration that repeats a set number of times, known before the loop starts; in Python, a for loop such as for i in range(5).
Counter
A variable that counts how many times something happens, set to 0 before a loop and increased by 1 each time, as in count = count + 1.
elif
Python's keyword for "else if": an extra condition in a selection statement, tested only when every condition above it was False.
else
The final branch of an if statement, which runs when none of the conditions above it were True and needs no condition of its own.
Exponent
The power a number is raised to; Python works it out with ** (^ in the J277 reference language), so 2 ** 3 gives 8.
for
Python's count-controlled loop keyword: it runs the indented block once for each value in a sequence, such as each number produced by range().
if
Python's selection keyword: it tests a condition and runs the indented block beneath it only when that condition is True.
Infinite loop
A loop whose stopping condition is never met, so it repeats forever and the program stops responding; often caused by never updating the loop variable.
Integer division
Division that gives only the whole number part of the answer and discards the remainder; // in Python and DIV in J277, so 17 // 5 gives 3.
len()
A built-in function that returns how many items are in a list, or how many characters are in a string, spaces included.
List
An ordered collection of items stored under one name, each reached by an index counting from 0; Python uses lists where J277 pseudocode uses arrays.
lower()
A string method that returns a copy of the string with every letter in lower case, leaving the original string unchanged.
Modulus
The remainder left after one whole number is divided by another; % in Python and MOD in J277, so 17 % 5 gives 2.
Nested loop
A loop placed inside another loop, so the whole inner loop runs once for every single pass of the outer loop.
open()
A built-in function that opens a file in a chosen mode, such as "r" to read, "w" to write or "a" to append, and returns a file object.

And 20 more in the topic glossary, at the back of the pupil workbook.

Common mistakes

Where pupils go wrong.

Each of these is written on a wall of the lesson where it is taught, so a pupil meets the mistake and its fix together.

  • Printing and variables: Leaving the quotation marks off, so Python hunts for a variable with that name instead.
  • Printing and variables: A second assignment replaces the value, it does not add to it.
  • Printing and variables: Reading two answers into the same variable, so the first one is lost.
  • Printing and variables: Joining a number to a string with +, which Python refuses to do.
  • Printing and variables: Adding to what input() handed back without casting it first, which joins the digits on the end instead.
  • Printing and variables: Printing the lines in a different order from the one the task asked for.

Using it

In the lesson, at home and in intervention.

For teachers

  • The unit's lesson PowerPoints, worksheets and lesson plans, in the Teacher Portal.
  • Set any lesson for a class with a due date, and see who has finished.
  • Reports show each station as Secure, Revise or Focus from pupils' first attempts, so a small group can go straight back to the right one.
  • Ask for a teacher key

For pupils

  • Sign in with the card your teacher gives you and open any lesson in this topic.
  • Write each key fact in your own words on the worksheet before you check it.
  • Every question is checked as you answer, and the next one opens when it is right.
  • Pupil sign in