0% found this document useful (0 votes)
13 views12 pages

CSC - Prog in Scratch

The document outlines learning outcomes for programming in Scratch, focusing on using sensing blocks, mathematical operators, and variables. It provides step-by-step instructions for creating scripts that perform tasks such as bouncing a ball, counting word lengths, and generating random numbers. Additionally, it emphasizes the importance of reasoning and decision-making in programming.

Uploaded by

Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

CSC - Prog in Scratch

The document outlines learning outcomes for programming in Scratch, focusing on using sensing blocks, mathematical operators, and variables. It provides step-by-step instructions for creating scripts that perform tasks such as bouncing a ball, counting word lengths, and generating random numbers. Additionally, it emphasizes the importance of reasoning and decision-making in programming.

Uploaded by

Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Programming in Scratch

LEARNING OUTCOMES
The student will be able to:
• use the sensing block palette. • bounce the ball up and down.
• use mathematical operators in Scratch. • count the length of a word.
• compare values and create variables. • generate random numbers.
• apply reasoning to make decisions.
- ---- --
In the previous class, you learnt about the different actions a sprite can perform on the
Scratch stage. You also learnt how to change the background , colour, direction , costume,
etc., of a sprite. In this chapter, you will learn how to perform the various mathematical
operations, like addition, subtraction, multiplication, division, and apply condit ions to get
the solution to a problem.

t} Using Sensing Blocks


The Sensing block palette has light blue colour-coded blocks, which are used to sense
the keyboard input while executing the script. The ft., v~..r,.--·t:J block prompts the user
to type input using the keyboard and D
block stores the keyboard input. The question
appears in a speech bubble on the screen. The program waits until the user types his
response in the Input box, and press the Enter key or click on check mark 0 . Let us create
a small script by using the sensing instructions and execute it.

❖ Delete the Cat sprite from the stage.


❖ Click on the Choose a Sprite O icon and add the Kai sprite from the People folder.
Choose the appropriate costume, Kai-a for the sprite from the Costumes palette.

Y','1~re should I go?

NY - tor • ,eann

Figure 6.1: Script for the


Sprite Figure 6.2: Sprite Displaying Question and Answer on the Stage

❖ Select the Stage thumbnail on the left and click on the Choose a Backdrop C, icon,
import the School backdrop on the stage.

Cyber Quest I KIN


,•. Create the script by dr .
· e,r: -._ aggmg and placing the three blocks as shown in Figure 6.1 .
❖ The .__,., ~
block enables t he user t o type input with the help of a keyboard.
❖ nd
Drag a place th e ~"' block on the text field of the block. Click on
the Green Flag (Go) but ton.

❖ The message "Where should I go?" gets displayed on the stage along with a text box.
❖ th
Type e answer 'To my friend's place" in the text box. Press t he Enter key or click on
the check mark Q present on the answer text box.

❖ The answer will be shown in the speech bubble on the stage for a specified number of
seconds.

~) Using Mathematical Operators


Blocks in the Operators block category are round in shape.
They are light green colour-coded blocks and used to solve
( I )-{ Subtraction )

mathematical equations. These blocks can easily be placed in


( I }---{ Multi plication )

the value box of any other block. Let us perform calculations


in a Scratch project using these blocks.
( I H Division

❖ Open a new file in the Scratch window. Delete the default Cat sprite. Click on the
Choose a Sprite O . Select the category Animals from the Choose a Sprite dialog box.
❖ Select the Duck sprite from the options.
❖ Drag the I block from the Events block category and place it in the Scripts
area.
---------
❖ Pull the say
~ blocks from the Looks block category and snap
C:, la G serooos
and
them together underneath the ~ block. G
❖ Type the message "The answer of 1+1 =" in place of 'Hello!" in the SJ'( CD ru G -.eanlS

block.
❖ Click and drag the { # ) block from the Operators block category and snap it inside
~
the block.
I
..
___ ---__,
r L'I :j i.-e

I:
______ _

~ The ans1,•;er or 1• 1 = fof e seconds


~
sat O +O
Figure 6.3: Sprite Adding Two Numbers on the Stage

~ I Cyber Quest
--r.w:::a:ii5LM_J • ·• a a -=

❖ Type the numbers inside the block as shown in Figure 6.3 on the previous page.
❖ Click on any block to run the script and observe the sprite calculating the given numbers.
❖ Ch h . . l · change in the result.
ange t e numbers and observe the spnte d1sp ayrng a
❖ Similarly, you can use the other blocks to perform subtraction C X ) ' multlplkation
CX >, and division cX >from the Operators block category.
IP) Comparing Values
The Operators block palette also includes blocks to compare the numbers. In Mathematics,
you use less than ( <), greater than (>), or equal to (=) sign to compare two numbers.
Similarly, in Scratch, the < X ) (less than) block reports true if the first value is less than
the second value, the ( # ) (equal to) block reports true if the two numbers are equal,
and ( # ) (greater than) block reports true if the first value is greater than the second
value. These blocks are known as 'Comparison blocks'. Let us make use of the comparison
blocks:
❖ Create a script by dragging the blocks as shown on the left side in Figure 6.4 and type
the numbers inside the ( # ) (less than) block. Click on the Green Flag (Go) button
to run the script.
❖ Likewise, create another script using the ( # ) (equal to) block as shown on the
right side in Figure 6.4 and execute it.
----- r::= ---------
.
-

2 111::H I

Figure 6.4: Sprite Comparing Numbers

IP) Generating Random Numbers


You can also generate a random number from a specified range by using the e it i• I § 10)
block from the Operators block category. Let us see how the sprite itself chooses the
random numbers with the help of this block.

1
Place the blocks in the Scripts area as
shown in Figure 6. 5 and change the
values.
❖ Click on the block and you will see
the sprite speaking random numbers
between 1 and 50. Figure 6 ·5 : Script for Sprite to Say Random Numbers
t) a,anging l.tJc lion Randomly
the ;;t:a:ie.
+ '1~ am al!.o w--e the ♦I .\• ti • ) ""'" tD specify a· I •andom location of a ,p..... te on
..,
~ Delete the Duck sprite c:1_,.. ij ada
_ Starfish. ~prite on the stage.
zY on -"'= b·oa #11\ randomly change the x and
~ Adding - f I · IS J blr ~
.11 ,on on the stage.
~
y co-or d1naw of the ~pnte''
., ., pc't
t e Scnpt area to create the script as shown in Figure 6.6
1, Drag and place the bloc~,. 10 · h ·
and e1ecute 1t to ob"er, th
J e e spnte
. changmg . ,ts
. tocat1on,
. -----
randomly.
••

Figure 6.6: Script for Sprite to Change Loca1ion

t) Bouncing the Ball Up and Down 0


To bounce a ball all around the stage you can use the Ci } •§ • ) block along with the
other blocks. Create a new Scratch project using the Beachball sprite and the blocks as

shown in Figure 6. 7 . ---------

II
I

-__ _
II
I

.; -, C> -
r
lI
I I

Figure 6.7: Script to Bounce the Ball Randomly

t) Counting Length of a Word


Scratch blocks provide the facility to count the
letters that are used to form a word. For example,
the word Encyclopedia has 12 letters. Let us create
a script (as shown in Figure 6.8) to display the total

number of letters. Figure 6.8: Script for the Sprite


+ Open a new file in scratch by clicking on the
ii)
File> New.
IIOaLI.C:vber_Quest r;•, ;s ; ; : & ;:
Backdrop G iron and ad()
choose a
❖ ~lect the :;t.;ge thumbnail and click on the oK. . bl k
Bed roomJ from the Indoors cate n. Clld< on k from the Sens1ng oc Palette
- - -~ ~ bloc
❖ Se•~ct the Code tab and drag the liil~;;....---
ana drGp it on the Scripts area. t field of the block·
❖ Tip~ the t~/t Can ;ou gue::5 an'} tong wor ·
d7'' in the tex
!f~.~.;,-:;;.~,r--,.,

❖ Drag the blocr from the Looks


b!oclr categor; in the ~cript area. Pier the C::, •.
blocr from the Sensfng category and place it
nhere th€:' Hellof" te/t is 'Nritten .
❖ A~ain, place the block
underneath the zrfpt. Change the te1t ''Hel!ol"
to ·•can 1ou count the number of letters?",
❖ /... dd the Figure 6.9: Typing tho Input
block.
❖ tk."11, aeafn, placJ? the block fn
the Scrfpt~ area and add ~ ) block from the Operators block to the text box
<Jf block a~ shown fn Ffgure 6.B.

❖ , low, drae the C::, bLod: from the Sensf ng block and place it on top of the tc.ixt box

~ v10rd.
c.11cr on any bloc¥ to run the script and obsr1rve the sprfte displaying the length of the

Ffuuro 8.1 O: 8prlt,, Counting tho Lon th


Q of a Word
•} Making a Variable
Y<Ju rnl~ht hclve ob-,ervcd that whfl<• <..ro• !,fr,u tho dfff
• " !) ... erent lcv ·l f
c s O a computer game, thr
-
!Jc ore the player r•fther lncrca~c:, or dc•creases ft
<Jf ,
1s displayed on the screen at the t'rtd
of the- gam<'. To store thc:,e scorc_. values varfabt ·
, es ar~ used.
A varfable fs a placeholder In Scratch\ rTl(•mory th .
Vi!rlablcs can hold one value at a time. These v l at f:, used t o store a chanoina value.
a ues can b . e-, .,
/text). e e, th er numbers or strings
70

11J/,
,:· In ~crate~. the Vari ables block category is used to create - .
vanables. m a project · Vana
· bl es are represented by blocks,
shaped hke elongated circles, uniquely labelled by the user.
Let us observe the complete process of creating a variable. • Cl ,
❖ In the Variables block palette, click on the Make a Variable
Fi J
0

J
block. The New Vari able box appears.
❖ Type any suitable name like 'N ame' fo r the vari able in the
Variable name t ext box. Select a button specifying whet her
-----
-••U11
the variable is For all sprites or For this sprite only. Click
Figure 6.11 : Making a New
on OK. Variable
❖ The 'Name' block will be added under the Variables block
menu.
❖ Now, drag the block as shown in figure 6.13 to creat e a script, using the different block
palettes.
❖ Click on the Green Flag (Go) button to run the script.

New va riable name

II ~ _]

• For all spntes For this spnte only

cancel •

Figure 6.13: Using Variable in Script


Figure 6.12: Creating Variable
❖ Type your name with the help of the keyboard, in the answer box displayed on the

stage, and press the Enter key.


❖ The sprite will speak the answer in a speech bubble and it will be stored under the

...--
variable name in the top-left corner of the stage.
---- :i e
. ,. ..

--
•• t " 1111
~ 1'I :,
I - c.,

li Variable stored

11w;
--v:, :;.;J-

I
~-~ - ~
t
Figure 6.14: Sprite Storing Name in Variable Name Box
I
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - , 71 - -
~) Applying Reasoning to Make Decisions
. . .
E\ e"'-1 one makes cec·sio~s irl caily life. Some ceas,ons are so ce,"'e-a
~ · . . ~at _\ Oi.. J-lardv
l .. ... ,
t?.ke
a'"'\ t;'""'e tc cecice on them. But sometlmes when a proo lem 1·s co rnp,e\.. 't_ ""ee'--s ,, ,soot:11


a:"'d- exoere'."'ce to take aee1s10ns.
. . . .
Difficult . .
s1tuations ,r eqU1re
. mo
• ..e .. easo!1ir.o =>
anl.J s, ,lS .. o
_
. the help or~ a s1mp
so~\ e :yc::,,e:ns. Let us uriderstand t:iis w1th · le mathematica~ eq1..;at'0"'.

You can so;\ e siniple e<;uations quickl1• lil-.:e:


2.0 ~ 20 = 40 20 .· 4 = 5
50 - 20 = 30

'
Example
\\'hen the mathematical equation is cor.ipla. it needs 'ig~t reasor,ing. to sol\ e it.
12 • 65 - (40 - 280 4) + 22 - 6 23
$

Here. you need to follO\\' proper mathematical rutes to obtain the correct sotution .

Let us take anoH1er situation. Suppose. you have to select two hobbies from the gi\ en list.
How ,,~n you decide which one to choose?
A B
Indoor activities Days Outdoor activities Days
aay modelling Monday Yoga Wednesday
Salad making Wednesday Karate Monday
Oil painting Monday Aerobics Wednesda)•
Wednesday

I
Dance G)1Mastics Monday

There are certain conditions and rules to be followed by every student before making
~pte the selection of the hobbies from the given list of eight hobbies. The rules to select the
combination of hobbies are as follows:
❖ Each student has to select at least two hobbies.
❖ The selection of one hobby from each section is mandator,.

❖ The periods for two selected hobbies should not fall on the same day.

Here, keeping the choice of the selection of hobbies, the student has to determine Whether
the two hobbies are a valid combination or not.

Uk~se,. pr~ramming in a co~pute.r language includes logic and decision-making. In


log1cal thmkmg, you should first 1dent1fy the main steps and then work out the details of
each step.

C~Que\t f1i11
Look at the shapes given h w the given steps:
Task ere . To find the nex t shape, you should follo

Read the problem ca refu ll y. Here , three shapes ?•


.
are g1ven. Wha t comes nex t in th e sequence?
Identify
❖ Goal: To find the fou rth sha pe m . t he sequence.

. .
Information: The sequence of th e shapes 1s g1Ven.

❖ In the .sequence ' the fi rs t shape has three sides, the second shape has four sides , and
the t h1rd shape has five sides.
❖ Condition: In the se quence , the number of sides of the shapes increases by 1.

Solve -1
tion
To achieve the goal by using the given informa
and follo win g the con ditio n.
❖ Reasoning: The nex t shape should have six
sides, i.e. , 5 + 1 = 6.
Explanation
k out the solu tion in a step -by- step manner. This proves tha t with logical reasoning,
Wor
. In Scratch too, you can crea te projects with
you can arri ve at the solu tion to any problem
g.
the help of the blocks using logical reasonin

~ Applying Condition in Programming


to
n is to be applied. It allows the program
To put a che ck on any pro blem , a conditio
acti on, bas ed upo n the user's inpu t. Scra tch provides various blocks enabled with
select an
hen ', 'for eve r-if' , and 'if-e lse' . These are the
conditional pro gra mm ing concepts, like 'if-t
block pale tte.
conditional bloc ks pre sen t in the Con trol
n evaluates to true.
In the = block, the script will execute, only if the conditio
elon gat ed diam ond -sha ped bloc ks of the Sen sing block pale tte can be placed as a
All the
condition insi de the Con trol blocks.
Let us observe the m in a pro ject .
the Spo rts category as
+ Open a new file in Scratch. Imp ort the backdrop Soc cer from
shown in Figu re 6. 15.
·t and add soc cer Ball spri te from the Spo rts category on the stage.
+ De lete Cat spn e .
. . by put ting valu e in the S1ze box.
Red uce 1ts s1ze
73
❖ Drag the ~~.:.\,t' block to the Scripts area. Place the block beneath it.
❖ Add the ._..__. block from
the Motion category. Change
the value to 15.

❖ Place the - ~ conditional


block beneath the ._..,.._
block.
c:~,~,
❖ Drag the -
block from the Sensing block :

I -- -
- --
~ & ., ... ...
-
palette, and place it over the - -F~ - 6.15 . Changing the if Condition of the Script
1gure
value box in the ~- I block
to check a condition and take decision.

❖ Select the edge option from the drop-down menu of the block.
The - DdiDg ""9e•?- block lets you check whether t he sprite is touching the edge of the
stage or mouse pointer.
❖ Drag the
block from the Motion category and place it beneath the
block. Change the value from 15 to 5.
❖ Drag the
block from the Sound category and place it under the
block.
❖ Drag the
~
,f on cd9.,., bounce
block from the Motion category and keep it outside the
block.

❖ Click on the Green Flag (Go) button ... and observe· the ball moving all around the
stage.

❖ Now, select mouse-pointer option from the drop-down list of the


block as shown in Figure 6.16. ~ ~ • ?

❖ Again click on the Green Flag -


(Go) button ,- and run the
script to observe the change.
❖ Observe that the ball is moving
and changing its colour only if
you place the mouse pointer
on the ball. Click on the Stop
button • to halt the execution.
Figure 6.16: Applying If Condition on the Sprite
AP r - - - - - - - - - - -
+ The Sensing block palett h .
keyboard input wh .l e a~ llght blue colour-coded blocks, that are used to sense the
1 e executmg the script.
+ Blocks in the Operators bl k
coded blocks and d oc category are round in shape. They are light green-colour
use to solve mathematical equations.
.
♦ The Operators block pal e t te also mcludes blocks that you can use to compare the
numbers.

♦ A variable is a placeho ld . Scratch ,s memory that stores a changing value. Variables


can hold l :r m
ne va ue at a t1me. These values can either be numbers or strings (text).
O

♦ When a word is saved i n a vanable . , 1t . called a string variable.


. 1s
.
♦ The main steps in logi ca l th·mk'mg are: task, 1dent1fy . , and solve.
'if-then '
• To put a_ check on any problem, a condition is to be applied. In Scratch
'
1 -e l se ' are the conditional blocks present in the Control block category.
'foreve r-1f' , and '·t

rarain
11jt' developer

A. Fill in the blanks.


1. The blocks in the .. ~0! .Cb . block category are round in shape.
2. The Sensing block palette has .. ~ .L,
colour-coded blocks.
3. The Cl[) block reports .. ~........... if the first value is greater than the second value.
4. When a word is saved in a variable it is called a .~.J J.~ .
5. Variables can hold ...........~............. value at a time.

• One • String Variable


Light Blue • True • Operators

B. Write T for True and F for False.


1. You cannot perform mathematical operations in Scratch.
CI]
2. All the blocks in the Operators block category are light blue in colour.
(TI
3. Scratch prole s the facility to count the letters that are used to form a word. [iJ
◄. You cannot create variables in a Scratch project .
[D
S v athema tical values using the blocks of the Operators r::7
· ,ou can compare m
LU
block palette .
Select the correct option .

1. The block to add two numbers are located unde


r the ........................ ...... block menu.
a. Operators ✓ b. Sensing c. Pen
2. The .............................. block is used to calculate
the product of the two values.
a. ( *) b. es ·\ I IO 10) C. ( * )✓
3. The Operators block palette has ........................
...... colour-coded blocks.
a. Light Green ✓ b. Blue c. Red
4. The .............................. block palette is used to
create variables in the Scratch proje ct.
a. Sensing . b. Variables ✓ c. Pen
5. All the elongated diamond-shaped blocks are
placed as a .............................. , inside the
Control blocks.

a. Condition b. Statement/ c. Variable


D. Application- based questions.
1. Kartik is learning to code in Scratch. He want
s to create a new proj ect, which displays
random numbers on stage. Sug~est the block that
he can use for the same.

· ·~ · ·ll.ocJ.t.,...............................................................................................................
2. Priyanka wants to create a new variable
'Name' in her Scratch proje ct. Suggest an
appropriate block for her to do the same .

.....<IJ':1:J..~ ....vCl ....k.O ~o .lJL ........................................................


........ ..............................
································································································································
··································
E. Answer the following questions.

1. What is the purpose of using a variable?

············································································································.···················
···································
································································································································
··································
································································································································
··································
2. What steps will yo u f ollow to solve a problem?

·······························································································································
········ ·································································································································
······························································································································
3. LiS t th e names of any three blocks that you can use to compare values.

·················· ················································································································································
··································································································································································
··································································································································································
4. Why do you use conditions in your scripts?

··········· ............................ ~·· ..... ············ ............................................................................··············· ............


-
··································································································································································
··································································································································································
5. Write the names of the different blocks that are used to perform conditional programming

in Scratch.

·····················································································································•!••··········································
·······•··························································································································································
··································································································································································
6. What do you mean by string variable?

··································································································································································
··································································································································································
..................................................................................................................................................................

Ill(.. ,Cybor Quest , , ,


_ _ _ _.,.,~ll!l"'Jll;"ID'l',I~.......- - - - - 77 - - - - -
~

You might also like