section 3 calculations national 4/5 scratch course

14
Section 3 Calculations National 4/5 Scratch Course

Upload: barry-booker

Post on 29-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Section 3 Calculations National 4/5 Scratch Course

Section 3Calculations

National 4/5

Scratch Course

Page 2: Section 3 Calculations National 4/5 Scratch Course

What you should know after this lesson

• How scratch stores numbers

• How to use variables in calculations

• What operators do

• The importance of sequence in calculations

Page 3: Section 3 Calculations National 4/5 Scratch Course

Variables

These are storage locations in RAM, controlled by the programming language.

What types of data might we need to use with our programs?

The main ones we will be using are– Numeric– String

Page 4: Section 3 Calculations National 4/5 Scratch Course

Numeric

• Are used for calculations.

• If you need to use a piece of data in a calculation you should use a number variable.

Page 5: Section 3 Calculations National 4/5 Scratch Course

Scratch Variables

1. Click on the variables tab

2. Click “Make a variable”

3. Type the name you want to use for the variable

The scratch language is able to work out the type of variable we are using and as a result it only has the one type of variable

Page 6: Section 3 Calculations National 4/5 Scratch Course

Displaying Variables

• We can get any sprite to speak by using the say block from inside looks.

• Variables can be displayed on the stage for example to display information useful to the user.

Page 7: Section 3 Calculations National 4/5 Scratch Course

Calculations

• For this task we are going to add two numbers together

• Create a new scratch project and add two new variables called first and second

• Add the script shown below

Copy the program into your jotter and answer.

1. What does the program do?

2. Why do we need First & Second?

Page 8: Section 3 Calculations National 4/5 Scratch Course

Other Operators

• Copy the blocks on the right into your jotter.

• Write beside each one what it does

• How could we do bigger calculations?

Page 9: Section 3 Calculations National 4/5 Scratch Course

Combining Operators

• Scratch Operator blocks (+-*/) can be combined to make more complex calculations.

• Simply drag a block into the white box.

• Remember the BODMAS rules from maths.

• Brackets ()• Of ^• Division /• Multiplication *• Addition +• Subtraction -

Page 10: Section 3 Calculations National 4/5 Scratch Course

Task

• Calculate the answer to the following problems, write the answers in your jotter. (you can use a calculator)

• Enter the calculations into scratch and check your answers

1. 5+4

2. 5*4

3. 5+4-3

4. 34+3*6

5. (34+3)*6

6. 40/5 + 4

7. 4+40/5

Page 11: Section 3 Calculations National 4/5 Scratch Course

How can we get it to display the full sum as the answer?

• You can add join to join to make a longer sentence.

• To drag the whole script block drag the lowermost block.

• Edit the program to subtract, multiply & divide. Save it in your network area.

Page 12: Section 3 Calculations National 4/5 Scratch Course

Assignment of variables

• Variables can be assigned values using the set block.

• Variables can be assigned the results of a calculation as well as the answer to an ask block.

Page 13: Section 3 Calculations National 4/5 Scratch Course

Review Questions

Copy and answer these questions in your jotter.

1. Where does scratch store numbers?

2. What is assignment?

3. What do arithmetic operators do?

4. Why is the sequence of calculations important?

Page 14: Section 3 Calculations National 4/5 Scratch Course

Tasks

Create scratch programs to do the following (save each in your network area).

1. Calculate the area of a rectangle

2. Calculate the square of a number

3. Calculate the sum of three numbers

4. Calculate the average of three numbers