Sequence 2 - Lesson 3: Variable Counting
Learning Intention
I can use a variable to make Picoh count
I can use a variable to make Picoh count
Introduction
Explain that we are going to make Picoh count. For this we are going to be creating a program that uses a variable.
You might want to discuss the use of a variable to keep and alter a score in a computer game.
Explain that we are going to make Picoh count. For this we are going to be creating a program that uses a variable.
You might want to discuss the use of a variable to keep and alter a score in a computer game.
To start with we need to set the value of the variable. We can start our program with a when green flag clicked instruction. First, we need a set Count to 0 instruction. This means we will start counting at zero. Next, we need to make a loop where we continually increase the value of ‘count’ by 1. We do this using a forever instruction and a change Count by instruction with the value set to 1. We now need to test our code by clicking the green flag. Once successful, we can
File, Save As - countinones
We can now use our first variable program as a skeleton to make other counting programs using a variable.
File, Save As - countinones
We can now use our first variable program as a skeleton to make other counting programs using a variable.
Activity
1. Can you write some code to make Picoh count in twos?
2. Can you write some code to make Picoh count in fives?
3. Can you write some code to make Picoh count in tens?
4. Can you write some code to make Picoh count in a 3 digit number?
5. Can you write some code to make Picoh count in a 4 digit number?
1. Can you write some code to make Picoh count in twos?
2. Can you write some code to make Picoh count in fives?
3. Can you write some code to make Picoh count in tens?
4. Can you write some code to make Picoh count in a 3 digit number?
5. Can you write some code to make Picoh count in a 4 digit number?
Extension
Can you change the number that Ohbot starts counting from? Can you make Ohbot count in ones starting from 20?
If Ohbot wants to start counting from 20, which part of the code do you think we
have to change? (set Count to). Remember to set the tick next to the ‘Count’
variable on the Data palette so you can watch the counting in the display.
File, Save As - countfrom20
We can now use this knowledge to complete other counting tasks.
Can you change the number that Ohbot starts counting from? Can you make Ohbot count in ones starting from 20?
If Ohbot wants to start counting from 20, which part of the code do you think we
have to change? (set Count to). Remember to set the tick next to the ‘Count’
variable on the Data palette so you can watch the counting in the display.
File, Save As - countfrom20
We can now use this knowledge to complete other counting tasks.
Extension Activities
2. Can you make Ohbot count in twos starting from 30?
3. Can you make Ohbot count in fives starting from 25?
4. Can you make Ohbot count in tens starting from 100?
5. Can you make Ohbot count in 125s starting from 1000?
2. Can you make Ohbot count in twos starting from 30?
3. Can you make Ohbot count in fives starting from 25?
4. Can you make Ohbot count in tens starting from 100?
5. Can you make Ohbot count in 125s starting from 1000?
Plenary
Encourage children to share their programs with the class and discuss ones that don’t work, work partially or have used a different algorithm to reach the same outcome. Encourage children to talk through how they work block by block and work as a class to debug a program to improve it.
Encourage children to share their programs with the class and discuss ones that don’t work, work partially or have used a different algorithm to reach the same outcome. Encourage children to talk through how they work block by block and work as a class to debug a program to improve it.