introduction to scratch - whitworth · •in scratch, is the name of the variable, and it will...

29
Introduction to Scratch

Upload: others

Post on 17-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Introduction to Scratch

Page 2: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Familiarising yourself with ‘Scratch’

Instructions and Controls

Scripts Area

Sequence of Instructions

SpritesThe Stage

Page 3: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

If a computer is a box…

…think of a program as a man inside the box!

Page 4: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

…and programming is all about instructing the man to do what

you want!

“Tell me what to do and I will do it!!”

Page 5: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

The man in the computer (program)

thinks just like a human.

If we taught the man how to have a conversation with the

computer user, what would be the first thing we would tell him to

do?

Page 6: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs → Storage → Process → Output• Conversations start with a question.• In other words the man in the computer might

ask the user for some information (INPUT).

• Example:“What is your name?”

The user would then type IN their name!

INPUT “What is your name?”

Page 7: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs → Storage → Process → Output

• Then the man in the computer will store the answer in its brain (STORAGE) and think about how to respond (PROCESS).

1. Remember the answer (STORE IT)

2. Think about how to respond (Process)

Page 8: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs → Storage → Process → Output• The man in the computer would finally

respond (OUTPUT).

• Example:“So, your name is BOB! What a great name!”

The computer would display this on the screen (OUTPUT).

OUTPUT

Page 9: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs → Storage → Process → Output• All programs work in this way…• Think of a word processor:

INPUT

STORAGE/PROCESS

OUTPUT

1. Users can press a letter on a keyboard (input)

2. The computer stores this event and decide how to respond (storage/process)

3. And then display the letter on the screen (output)

Page 10: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

• The ASK script asks the user to enter (input) a value into scratch?

Inputs → Storage → Process → Output

Page 11: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

What do you get when you ask a question?

ANSWER!

Once you have inputted a value into scratch it is stored in a ‘variable’ called answer.

This is what the script looks like

Inputs → Storage → Process → Output

Page 12: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

What is a variable?• In programming, a variable can be thought of

as a storage box.• The box may be given a name, and it may

hold various different things.

• In scratch, is the name of the variable, and it will store whatever you type into scratch.

Variable called ‘ANSWER’ Contents is anything we type in

Storage

Page 13: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs → Storage → Outputs• Which of the following scripts do you

think will help us output a value onto the screen?

Page 14: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

The Join Script

• We can also join words and the ‘ANSWER’ together to create sentences:

Page 15: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Moving your Sprite• In programming, things always happen in a

set order – a sequence.• Sequences are first written as a flow chart

and then programmed in a game.• If we want to move a sprite left the following

sequence would have to occur:

Press right arrow key

Sprite faces to the right

Sprite moves a step to the right

In Scratch, we program the sprite like this:

Page 16: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs, Outputs, Variables and Decisions

Page 17: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs → Storage → Process → Output• In Scratch, which of the following scripts

will help us program the man (inside the computer) to demand an input from a user?

Page 18: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

• The ASK script asks the user to enter (input) a value into scratch?

Inputs → Storage → Process → Output

Page 19: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

What do you get when you ask a questions?

ANSWER!

Once you have inputted a value into scratch it is stored in a ‘variable’ called answer.

This is what the script looks like

Inputs → Storage → Process → Output

Page 20: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

What is a variable?• In programming, a variable can be thought of

as a storage box.• The box may be given a name, and it may

hold various different things.

• In scratch, is the name of the variable, and it will store what ever you type into scratch.

Variable called ‘ANSWER’ Contents is anything we type in

Storage

Page 21: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

• Which of the following scripts do you think will help us program the man (inside the computer) to output a value onto the screen?

Inputs → Storage → Process → Output

Page 22: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Summary

INPUT SCRIPTS:

STORAGE SCRIPTS:

OUTPUT SCRIPTS:

The “join” script is a nice extra to combine set text with the user’s text to form sentences when outputting to the screen

Page 23: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

IF statements are how programs make decisions (process data).

IF this occurs, I will do thisELSE, I will do that

IF – ELSE statements allow programs to make decisions based on certain conditions occurring.

Inputs → Storage → Process → Output

Page 24: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

What’s going on here?Program asks the user to input a number from 1 to 3 Program stores their input

in the variable called ‘answer’

IF answer contains 1, the program will display a message

IF answer contains 2, the program will display a different message

IF answer contains 3, the program will display a different message

Page 25: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Inputs, Outputs, Variables and Decisions

You are all going to be real computer programmers!!!

Page 26: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

Today• We will create a simple calculator in

scratch which will add two numbers together and display the result

2 5

Page 27: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

So how can we get our sprite to do the following?

Ask for a number?

Store the number?

Ask for another number?

Store the number?

Display their

‘Sum’

First issue:

Scratch only has one variable (storage box) “answer”.

Scratch can therefore only store one number!?

Number 1 Number 2We need 2!!

Page 28: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

What is a variable?• In programming, a variable can be thought of

as a storage box.• The box may be given a name, and it may

hold various different things.

• In scratch, is the name of a ready made variable, and it will store what ever you type into scratch.

Variable called ‘ANSWER’ Contents is anything we type in

Storage

Page 29: Introduction to Scratch - Whitworth · •In scratch, is the name of the variable, and it will store what ever you type into scratch. Variable called ‘ANSWER’ Contents is anything

So how can we get our sprite to do the following?

Ask for a number?

Store the number?

Ask for another number?

Store the number?

Display their

‘Sum’