Define and predict
Starting from Scratch - Lesson 1
Objectives
- To understand and explain key vocabulary linked to programming.
- To accurately read, predict and explain visual code to a partner.
Lesson 1 - Define and predict
Lesson 2 - Reading code
Lesson 3 - Modify your code
Lesson 4 - Sequencing and repetition
Lesson 5 - Plan your make
Lesson 6 - Review and refine
About this unit
This unit of work aims to build on the control and programming lessons that the children will have experienced in Early Years and Key Stage 1, and lay strong foundations for the rest of their computer science journey through Key Stage 2 and beyond. The lessons apply the PRIMM method of teaching computer programming. This is an approach developed by Sue Sentance, Jane Waite & Maria Kallia in their 2019 research paper: Teaching computer programming with PRIMM: a sociocultural perspective. PRIMM stands for:
Predict - Students discuss a program and predict what it might do, drawing or writing out what they think will be the output. At this level, the focus is on the function of the code.
Run - Students run the program so that they can test their prediction and discuss in class
Investigate - The teacher provides a range of activities to explore the structure of the code; this involves activities such as tracing, explaining, annotating, debugging, but with the scaffolding provided by an existing solution
Modify - Students edit the program to change its functionality via a sequence of increasingly more challenging exercises; the transfer of ownership moves from the code being not mine to partly mine as students gain confidence by extending the function of the code
Make - Students design a new program that uses the same structures but that solves a new problem (i.e. has a new function)
(Sue Sentance, Jane Waite & Maria Kallia (2019) Teaching computer programming with PRIMM: a sociocultural perspective, Computer Science Education, 29:2-3, 136-176, DOI: 10.1080/08993408.2019.1608781)
PRIMM promotes discussion between learners about how programs work, and the use of starter programs to encourage the reading of code before writing, therefore improving their comprehension of what code could do before they move onto adapting existing programs, and then eventually create their own based on the structures they have already looked at.
Introduction
Ask the class to think back to computing lessons they’ve had in the past (or anything they have learned from other places.) Ask the class - can you tell me any words that you remember that are linked to programming, even if you can’t remember their meaning?
Collect the words they come up with and display them as a list on the board. They may come up with words such as these:
- Algorithm
- Code
- Debug
- Instructions
- Predict
- Program (verb)
- Program (noun)
- Repeat / Loop
- Sequence
- Test
Explain that in this lesson we will be trying to make sure everyone understands the keywords that are important for this area of computer science. We will also be looking at different examples of code and trying to predict what they might do.
Key vocabulary - What do they mean?
Put the class into small groups of around 4 students. Give each group a copy of the Definition match activity. Explain that this sheet contains words that make up the key vocabulary for this unit of work. Ask them to look at all the words and the definitions for each word, which are mixed up in the wrong order. As a group, they should decide which is the correct definition for each word. They should link the correct words and definitions by drawing a line between them.
Give the children time to complete the activity and then go through each word, asking the class for their suggestions for the correct definition and then providing the correct answer. Answers are provided below and also in the lesson slides.
Algorithm - A precise step-by-step set of instructions for achieving a goal or solving a problem.
Code - Instructions for a computer written in a programming language.
Debug - To find and correct the errors in a computer program.
Predict - Say or estimate what will happen in the future or as a consequence of something.
Program (verb) - To give a series of instructions to a machine so that it will perform a task automatically. This could involve pressing buttons or writing code.
Program (noun) - A sequence of instructions written to perform a specific task on a computer.
Loop - A programming feature where one or more instructions are repeated, perhaps a certain number of times, until a condition is met or until the program is stopped.
Sequence - To place programming instructions in a particular order, with each carried out one after the other.
Test - To try something out to see if it works.
There are undoubtedly similarities between some of the words and concepts, which gives the potential for some confusion, but the key things to point out are that an algorithm is not specific to a computer. It can be applied to any situation where step-by-step instructions are given to solve a problem.
We can design an algorithm in our own words by drawing or writing it out in any way we like, but we then must use a programming language that a computer understands to turn the algorithm into code that a computer can follow. These sequences of code to achieve a specific task on a computer are known as programs. Apps we use and games we play on our devices are programs.
A useful analogy to help explain it is that of writing a story. You might plan out your story map first to show the order of events (the algorithm), then you write out the actual words in detail to tell the story (the code). You might edit it along the way to fix mistakes or improve it (debug). Then you'll have the finished work that tells the whole story (the program).
Be sure to also point out the difference between program as a verb and a noun.
Programming vocabulary bingo
Put the students into pairs and give each pair a copy of one of the six Programming vocabulary bingo cards and something to write with. The cards could be laminated and used with whiteboard pens so they can be used again.
Ask them to listen very carefully throughout the rest of the lesson, and if they hear you say any of the words on the sheet they should tick them off. They can call ‘bingo’ if they complete a line of words in any direction, or ‘house’ if they tick off all the words. Feel free to reward winners with house points or any other reward system you may use in your school.
Reading code 1
Like with other forms of literacy, learning to read code before attempting to write it is an important first step. Here we are going to have a look at a range of examples of code written in different formats to see if the students can make sense of the instructions in a program and make accurate predictions about what the code will do.
All these examples make use of visual coding blocks and should be things the students have seen (or similar to things they have seen) in Key Stage 1.
Let’s start with some code for a Bee-Bot and model reading the code to the class. If the children are not familiar with a Bee-Bot, explain that it is a small programmable robot. Directional buttons tell it where to go. You can create sequences of commands for a Bee-Bot. Also, remind them that we are now playing vocabulary bingo!
Show this code first.
Model reading the code, for example: “I can see that there are two instructions in this program. The arrows show me the direction that Bee-Bot will move in. So I predict that the Bee-Bot will move forwards two steps and then the program will end..”
You can use a real Bee-Bot or something like the Terrapin Bee-Bot simulator to demonstrate your prediction for the outcome of the movements based on the code. Here we've selected the blank Card Mat from the dropdown menu in the top left.
Say something like "I predict that the code in this program will move me forwards two squares to this square (point to the relevant square. Now I'm going to test the program"
Click the arrows to match the example code and then click Go.
It will move to this square:
"I was correct"
Let's try another one!
"There are four instructions in this program and the sequence goes from left to right. I predict that the code will make the Bee-Bot move forward two steps, then turn 90 degrees to the right and then move forwards one more step. Then the program will end. Now I'm going to test the program"
Again, model testing the code with a real Bee-Bot or the simulator (press the home button to move the Bee-Bot back to its start position and the cross button to clear any previous code from the Bee-Bot's memory).
It will move to this square if you are using the simulator:
"I was correct"
Let's look at one more, slightly more complex example with a Bee-Bot:
"There are seven steps to the code in this program and the sequence again goes from left to right. I predict that the Bee-Bot will move forwards, then backwards, then forwards again. Then it will do two 90-degree turns to the right. Finally, it will move backwards twice and then the program will end. Now I'm going to test the program"
It will move to this square if you are using the simulator:
Main task - part 1
Introduce the students to the student slides for their main activity. To access them they need to type this URL into the address bar of any web browser and press enter.
Read through the first two slides with them and make sure they know how to move through the slides. We'd recommend using the arrow keys if they are working on a computer, or you can swipe left and right if you are working on a tablet. The second slide contains an example to go through with them.
They should work in pairs (or small groups) and take it in turn to answer each question, verbally explaining the code on the screen. After each question, they should check if their partner agrees. If they do not they should explain why. The Bee-Bot questions will then ask for visual predictions of where the Bee-bot in each picture would finish if it carried out the program.
There are four questions for them to try based on Bee-bot style code. Then stop them and bring the class back together to have a look at reading another type of code, in this case ScratchJr, which they may have used in our Year 2 unit of work, Programming with ScratchJr.
ScratchJr is a free app that is available for most types of tablet. An unofficial desktop version for Mac and PC is also available here. It is exactly the same as the tablet version, apart from it does not include the Scratch cat character.
Reading code 2
Let's take a look at some different code. Show the class this first example from the lesson slides and ask if anyone recognises where the code comes from. Explain that it comes from the ScratchJr app, which they may have used before in Key Stage 1. It works differently to a Bee-bot and has many more code options which let you program the sprites to do a huge range of different things.
Model reading this code to the class. Say something like:
"There are five commands in this program and the sequence runs from left to right. The yellow block with a green flag is an input, it starts off the program when the green flag button at the top of the screen is pressed. The blue blocks then make the sprite move, the numbers below them show how far the sprite will travel. It moves one step to the right, then three steps to the left, and then one step up the screen. Then the program ends with the red block."
Here's how it looks when the code runs:
Here's a second one to model to the class:
Read the code with a description something like this:
"This code also starts with the input of pressing the 'green flag' button. Two movement commands of two steps right and then two steps up are then repeated four times by a counted loop. The program then ends with the red block."
Here's how it looks when the code runs:
Main task - part 2
Ask the class to return to the activity slides at tinyurl.com/readingcode1.
They should continue the questions from page 8 where they will find four examples that use code from ScratchJr. They should take each task in turn, explaining the code to their partner. They should then see if their partner agrees, and then check their predictions by watching the animated clip on the slide. After that, they should consider whether their prediction was correct (did the sprite do what they thought it would?), and if not, ask them to work out where they made mistakes with their partner.
Plenary
Finish off the lesson by reviewing the key vocabulary from the lesson, did you have a bingo winner?!
Review some of their answers to the main tasks, asking some students to read the code