Raspberry_Pi_Education_Manual

Notes:

Lesson 1.4: Maths Cat

Learning objective: You will learn how to use variables to store data for using in a program. You will also learn how to use operators to do simple sums. Resources: The default sprite “ cat ” on the default white background.

Do you find maths difficult?

Can you imagine what it would be like to be able to do millions of sums in seconds and always get them right? Even the most complicated sums you can think of?

Computers are fantastic at maths. In fact, maths is what they do best. We can program the Scratch cat to do maths. The cat will ask for some numbers and then do the sums. So, how are we going to put numbers into the program for the cat to use? When we input numbers (put numbers into a computer), the computer has to have somewhere to store them. Different people might input different numbers, so these numbers are going to be different each time. When programming, we store numbers in something called a “ variable ”. One way of thinking about a variable is as a box, or container, in which we can store numbers, letters or words. We may have more than one variable in a program, so we give them different names. The name can be as simple as a single letter (or as complicated as you like!). For example, if it is storing a number, we might call the variable “n”.

7 n n

7

In the diagram, we have stored the number “7” in the variable “n”. So we can now say “n = 7”.

In the example above, we created a variable called “n” and stored the number “7” in it. In Scratch, you would do this in two steps: first creating the variable “n”, and then using a block from Variables to set its value to “7”.

A beginner’s guide to Scratch

23

Made with FlippingBook flipbook maker