Introduction to Programming

advertisement
The Scratch Calculator
You are all going to be real
computer programmers!!!
www.computerscienceuk.com
This Half Term’s Project
• Computer Programming – The Scratch
Calculator
www.computerscienceuk.com
Lesson Objectives
Learning Objectives
• Understand how to create a sprite
• Understand how to create a new background
• Understand how to move the sprite
•
•
•
Understand how to input values into scratch
Understand where our inputs are stored
Understand how to output values onto the screen
Lesson Outcomes
• Create a simple program whereby the sprite (which can be moved
by the user) asks the user a few questions and responds to the users
answers.
Literacy – Key Words
Sprite
An object which can be programmed in scratch
Scripts
A piece of programming code in scratch
Inputs
Values which get sent from the user into the computer
Variables
The place where inputs get stored by the program
Outputs
The values which get sent from the computer to the user
www.computerscienceuk.com
Scratch
• Scratch is an application
which allows you to
‘program’
• It allows you to use and
create ‘Sprites’ which are
simply characters and
objects
• It allows you to program
these Sprites so that they
move and interact with
each other and the user.
www.computerscienceuk.com
Familiarising yourself with
‘Scratch’
Instructions
and
Controls
Scripts Area
Sequence
of
Instructions
The
Stage
Sprites
www.computerscienceuk.com
Designing a new sprite
www.computerscienceuk.com
Designing a new background
www.computerscienceuk.com
How do we program?
• Programs are not that different from us.
• In fact, programming is all about
teaching the computer to think just like
us (humans)…
www.computerscienceuk.com
If a computer is a box…
…think of a program as a
man inside the box!
www.computerscienceuk.com
“Tell me what to
do and I will do it!!”
…and programming is all about
instructing the man to do what
you want!
www.computerscienceuk.com
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?
www.computerscienceuk.com
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?”
www.computerscienceuk.com
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)
www.computerscienceuk.com
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
www.computerscienceuk.com
Inputs → Storage → Process → Output
• All programs work in this way…
• Think of a word processor:
INPUT
1. Users can press a letter on a
keyboard (input)
2. The computer stores this event
STORAGE/PROCESS
and decide how to respond
(storage/process)
OUTPUT
3. And then display the letter on the
screen (output)
www.computerscienceuk.com
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?
www.computerscienceuk.com
Inputs → Storage → Process → Output
• The ASK script asks the user to enter
(input) a value into scratch?
www.computerscienceuk.com
Inputs → Storage → Process → Output
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
www.computerscienceuk.com
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
www.computerscienceuk.com
Inputs → Storage → Process → Output
• Which of the following scripts do you
think will help us program the man
(inside the computer) to output a value
onto the screen?
www.computerscienceuk.com
Inputs  Storage  Outputs
• Which of the following scripts do you
think will help us output a value onto the
screen?
www.computerscienceuk.com
The Join Script
• We can also join words and the
‘ANSWER’ together to create sentences:
www.computerscienceuk.com
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
www.computerscienceuk.com
Task 1
1. Open onto Scratch
2. Delete the cat and create a stick man
sprite.
3. Program it to ask you your age
4. Then get the stickman to reply by saying
something like, “Oh,
years old is well
old! I’m only 30mins old myself!”
5. Then try carry on programming some more
questions and responses.
20 minutes
www.computerscienceuk.com
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
In Scratch, we program the sprite
like this:
Sprite faces to the
right
Sprite moves a step to
the right
www.computerscienceuk.com
2nd Activity
• Create a new background, something
quick and simple.
• Program your sprite so that it moves up,
down, left and right when you press the
arrow keys.
If you finish early, be the teacher and help others!!
15 mins
www.computerscienceuk.com
Plenary
• How do you create a sprite?
• How do you create a new background?
• How do you program movement in the
sprite?
• Which script allows us to input values into
scratch?
• Where are our inputs are stored?
• Which script allows us to output values onto
the screen?
www.computerscienceuk.com
Homework
• Complete the Lesson One Worksheet
www.computerscienceuk.com
Download