Scratch Programming Tutorial
Scratch Programming Tutorial
ay
Jyoti and Tejas are planning
D
Sports to create a game called “Logic
Bingo” using Scratch programing
language. They start discussing
about it with Moz.
Tejas: We want to convert this into a Scratch project. Students have to find the correct
combination of games in four chances.
Jyoti: We will not reveal the rules for valid combinations to students. We will display only
the names of the games. They have to guess the rules and find a valid choice.
Moz: Good project. So how do you start?
74
Tejas: The main steps in our project are:
Step 1: Display the games.
Step 2: Repeat the following sequence four times.
i. Ask the student to enter the choice for first game. Receive the answer.
ii. Ask the student to enter the choice for second game. Receive the answer.
iii. Determine whether the two games are a valid combination.
iv. Display whether the combination is valid or invalid.
v. Keep score of valid choices.
Step 3: Display the final score.
Jyoti: We do not know the instructions for sub-setps in Step 2.
Moz: Let us start with sub-steps i and ii of Step 2. This is called receiving input from the
keyboard.
Tejas right clicks on the instruction and gets help for it.
2 3
Tejas: This is good. We can ask a question and also capture the answer given by the user.
Jyoti: Let us enter another question using the ask instruction.
Keyboard input
• ask and wait prompts users to type input using the keyboard.
CONCEPTS
• answer stores the keyboard input.
76
Creation of Variables
Tejas: What happens to the input entered for the first question. Is it lost?
Jyoti: I wish the computer can save the answer somewhere.
Moz: Sure it can. Check out the Variables block.
Variables
The variable blocks allow you to create variables and use them in
a program. The variables can store numbers or strings (sequence of
characters). A variable can be created such that:
• Only one of the Sprites can use it or all Sprites can use
o
the variable. Inf
77
Moz: Scratch allows you to save answer in a variable that you have already created.
Operators (A symbol that represents a specific action. For example, a plus sign (+) is an
operator that represents addition.)
Tejas: Suppose the name typed is “Jyoti” then I want to say “Hello Jyoti”. How do I get this?
Moz: You want to join two words and display it. Join is a string operator. Check
out these instructions in Operators block.
Jyoti checks the help for string operator join. Then she adds the join instruction to her scratch
program and executes it.
Tejas: How do we compare strings? We will need it for our project, to compare the user’s
answer with ours.
Moz: How do you compare if two numbers are equal?
78
Jyoti: Using ‘=’ (equal to) operator.
Moz: You can compare strings for equality also, just like numbers. Where do you find the
comparison instruction?
Tejas: In Control block.
Tejas and Jyoti write the following blocks to see how operators and control statements can
be used.
Script for the Cat Sprite Script for the Football Sprite
Conditional statements:
• if and if-else in the control block are used to check for a condition.
CONCEPTS
• If the condition is true the set of instructions after if are executed.
• Otherwise, the set of instructions after else are executed.
Moz: Explore the other string operators too. You may get some more ideas to show
comparisons.
Tejas and Jyoti explore the following string operators:
79
Logic Bingo by Tejas:
Tejas: Let us create a game called “Logic Bingo”. There are six Sprites for the six games.
Cat Sprite will ask a question and capture the response. An Instruction Sprite will give the
instructions of the game.
Moz: Have you decided on the variables that you will require for the game?
Jyoti: Since the player enters two games of his or her choice, we need two variables, game1
and game2, to save the choices.
Moz: What is the next step? How does the program start?
Jyoti: The program starts as follows.
Script for Script for both Stage after running the Script
Instruction Cat Sprite and the
Sprite game Sprites
Moz: Good.
Jyoti: We can use the same sequence and logic for the second choice of game too.
Moz: Correct. Go ahead and write the Scripts for referee and game Sprites.
82
Moz: Now that you have one choice, what should be your program for the next one?
Tejas: Program for choice2 will be the same as for choice1, except that player’s response will
be saved in variable game2.
Moz: That is a very good comparison sequence. First you are making sure there are no
duplicates. Next, since there is only one more invalid combination, you are checking for it.
Rest of the combinations are valid.
Tejas: We will now complete the game.
83
Final stage of Logic Bingo
Moz: Have you noticed there is one more option under the Variables block: ?
Tejas: Is it something like the lists we make for purchasing things from the grocery store?
Moz: Yes, it is similar to lists that we normally use.
Jyoti: We will click on it and make a new list. Let us name it as Mylist.
Moz: When you create a list you get eight different blocks under list. If you click on the help
for you can get the functions of all these eight blocks.
Lists (arrays)
CONCEPTS
• Use list blocks to store a list of numbers and strings.
84
Tejas: Let us write a program to get four items from the user, which can be taken while going
on a picnic.
Tejas and Jyoti explore the various commands for list and write the following program.
Moz: Good. Today you have learned to take input from user, use list and variables. Write
more programs and have fun! Chin Chinaki...
e
utcom
g O ll
rnin
u wi
n, yo
L ea l e ss o
this
ed
tudi
h ave s nde
r
e r you an ds u les
Aft le to: m ab
b g co
m Vari
be a
m s usin in) and
a J o
rogr s (like, .
te p r
Wri perato blocks for a
O
the able, lis
t)
e y b oard
i hk
(var oug
p ut thr
n .
ide i ram
Prov ch prog
r at
Sc
85
Level V Lesson 4 WORKSHEETS
1. Gargi has written a program to capture the input from the user. She has created
a variable named Input. What will be the final value of this variable after the
execution of the program?
a. Hello!
b. User name
c. User’s friend’s name
d. answer
2. The following is a small program. The last line of the program is missing. When
executed the user gave the name as Annie. If you want the sprite to say “Hello
Annie”, what should be the last line of the program?
3. A small program which compares two strings is given below. The user has
entered the name of two items he likes to eat. Can you tell what the Sprite will
say at the end of this program?
4. In the following program there are three variables: Choice1, Choice2 and
Game. When the program runs fully, what will be the final value of the variable:
Game?
a. Basketball,
b. 0
c. Football
d. 2
5. Here is a program to compare numbers. What will the Sprite say when the
numbers entered by the user are 250 and 500. Circle the correct option.
a. Choice1 is less than Choice2
b. 250 is less than 500
c. Choice1 is greater than Choice2
d. 500 is greater than 250
1
87
Level V Lesson 4 WORKSHEETS
7. The stage of the game Collide (which has Cat and Gobos as sprites), and the
scripts for the cat, yellow Gobos and the pink Gobos are given below.
Cat Script Script for yellow Gobo Script for pink Gobo
Using the scripts given above for the game Collide answer the following:
88
Level V Lesson 4 WORKSHEETS
8. You are given a Sprite “fantasy man”, costumes for the Sprite which are “extinct
birds and animals” and a list “avatar” with the names of the costumes and
jumbled up instructions for the Sprite. Arrange the instructions into a Scratch
block by:
1. Using the Sprite and costumes given.
2. Arranging the jumbled up Scripts such that the following actions are
repeated:
• The fantasy man asks the user to guess the next avatar that he would change
to from the list of extinct birds and animals given on the stage.
• The user guesses the next avatar and enters the corresponding number from
the list on the stage.
• Fantasy man changes to a random costume.
• If the guess matches the costume that the fantasy man changes to then he
makes a positive statement, else provides the name of the costume that he
changed to.
2
Scratch block of fantasy man
3 1
89
ACTIVITY Level V Lesson 4
90
ACTIVITY Level V Lesson 4
iv. Simple Electrical Circuits: Place all the components in the circuit to light up the bulb.
Scratch ---> Projects ---> Simulations ---> SimpleElectricalCircuits
Activities to do:
• Position the circuit components and light up the bulb.
• Change the program to introduce another bulb and light up both the bulbs.
Project
Do project 4.1, 4.2, 4.3 from lesson 8.
Explore!
1. Explore what are boolean operators?
2. Find out the fumctions of commands under
Operators block like , .
91
Teacher’s Level V
Corner Lesson 4
The purpose of this lesson is to teach students how to use the instruction blocks related to
conditional statements, variables, lists, operators and keyboard input, available in Scratch.
Students are already familiar with this programming language and understand that they
can make the computer do something using this activity.
Begin by revising the functions of different instruction blocks already taught. You can ask
them to write a small project to refresh their memory of what they already know. Tell the
students that they will now learn to use additional instruction blocks to write a variety of
interesting projects.
Start Scratch and open an existing project (e.g. Examples --->Speak up ---> Global warming)
that includes sensing and variable instructions. At this time, do not show the Script. Ask
them to observe the animation. Now show the Script area and ask them to observe if they
find any new instruction blocks, and of what colour. Ask them to which instruction block set
do they belong. Let them guess its functions, if they can. To do this, you can use the strategy
of think pair share, where students can partner with their classmate and do this activity.
Now explain the functions of different sensing options using the example mentioned in the
book. Right click on the different block and open the help screen and ask them to read their
functions. Do it for a couple of instructions and ask the students to explore the remaining
instruction blocks themselves. Similarly teach the functions of different variable options.
Give a demonstration of the Script included in the lesson to show how to use the different
instruction blocks.
Emphasize that it is important to plan and organise the different activities you want to do
using Scratch. Ask the students to write the Script for the Scratch project in their notebook.
Now ask them to exchange it with their partner and program using Scratch for each other’s
activity.
Further Reading:
http://scratch.mit.edu/
92