Saturday 7th October

Introduction to Variables

Today we are going to learn about a very important part of a computer program: variables.

Computer programs process information. Some of the information that is input, stored, and used in a computer program has a value that is constant, meaning it does not change

throughout the course of the program. An example of a constant in maths is pi because it has one value that never changes. Other pieces of information have values that

vary or change during the running of a program. Programmers create variables

to hold the value of information that may change. In a game program, a variable may be created to hold the score of the game.

Variables hold a specific type of information. The micro:bit’s variables can keep track of

numbers, strings, booleans, and sprites. The first time you use a variable, its type is assigned to match whatever it is holding. From that point forward, you can only change the value of that variable to another value of that same type.

A number variable could hold numerical data such as the year, the temperature, or your age

A string variable holds a string of alphanumeric characters such as a person’s name, a password, or the day of the week.

A boolean variable has only two values: true or false. You might have certain things that happen only when the variable called gameOver is false, for example.

A sprite is a special variable that represents a single dot on the screen and holds two separate values for the row and column the dot is currently in.

Activity 1 – Manual Score Keeping

Now we are going to play a few games of Rock, Paper, Scissors. Everyone should get into groups of 3 and have two players play the game and one should keep score. After a few rounds, swap who the score keeper is. Do this until everyone has had a turn at being the score keeper.

Now lets look at your score sheets. Can you identify what things on your sheet are constants and what are variables?

Activity 2 – Build Your Own Score Keeper

We can now begin to code using variables. The instructions for this are found here: Score Keeper game