CSC - Prog in Scratch
CSC - Prog 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.
NY - tor • ,eann
❖ Select the Stage thumbnail on the left and click on the Choose a Backdrop C, icon,
import the School backdrop on the stage.
❖ 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.
❖ 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:
______ _
~ 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
II
I
-__ _
II
I
.; -, C> -
r
lI
I I
❖ , 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
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.
II ~ _]
cancel •
...--
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"'.
'
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.
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
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
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.
rarain
11jt' developer
· ·~ · ·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 .
············································································································.···················
···································
································································································································
··································
································································································································
··································
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?
in Scratch.
·····················································································································•!••··········································
·······•··························································································································································
··································································································································································
6. What do you mean by string variable?
··································································································································································
··································································································································································
..................................................................................................................................................................