Raspberry_Pi_Education_Manual

Notes:

In this example, we set the cat’s score to 100 points by clicking on the cat sprite. But there are plenty of other ways to put a number into a variable. The method you choose will depend on how you want to use the variable.

Inputting the numbers

Your teacher has set you four sums. The sums are:

56 + 39 = 87 - 42 = 16 x 9 = 240 ÷ 6 =

We’re going to show you how to get Maths Cat to do this homework for you. Let’s start with the first question, 56 + 39. If you get stuck, refer to the image of the completed code at the end of this exercise.

First, create three variables, and name the first two “first_number” and “second_number”. You’ll use these to store your two numbers. Name the third variable “result”. This is where you’ll store the answer to your sums.

To input the first number you need to use a Sensing block to tell the user what to do. Drag the block “ask [What’s your name?] and wait” to the Scripts tab. Change the value to “What’s the first number?”. The answer given by the user is then entered to a variable, where it’s stored for use in your sum, by using a combination of a set “variable” block from Variables and an “answer” block from Sensing. Let’s see how.

Click on Variables, select the block “set [first_number] to [0]”, drag it to the Scripts tab and snap it to the previous block.

A beginner’s guide to Scratch

25

Made with FlippingBook flipbook maker