Page 49 - Code & Click - 6
P. 49
Relational Operator Blocks
Relational operators are used to compare two values or expressions. The result of these operators
is either True or False.
The relational operator blocks in Scratch 3 are:
Block Description
Returns ‘True’ if the first value is equal to the second value, else returns ‘False’.
Returns ‘True’ if the first value is greater than the second value, else returns
‘False’.
Returns ‘True’ if the first value is less than the second value, else returns ‘False’.
Logical Operator Blocks
Logical operators are used to combine two or more expressions containing relational operators.
These operators evaluate to either True or False.
Block Description
Returns ‘True’ if both the expressions are True, else returns ‘False’.
Returns ‘True’ if any one of the expressions is True, else returns ‘False’.
Returns ‘True’ if the expression is False and returns ‘False’ if the expression is
True. (Reverses the result of the expression)
The table given below illustrates the use of the logical operators taking the values X = 25, Y = 40, and
Z = 30 as example.
Expression Evaluation Result
X < Y AND Y > Z True AND True True
X > Y AND Y > Z False AND True False
X > Y OR Y > Z False OR True True
X > Y OR Y < Z False OR False False
NOT X > 30 NOT False True
Pick Random Block
The Pick random block, under the Operators category, picks a number between the
specified range randomly. For example, the pick random 20 to 50 block will randomly pick a number
from 20 to 50. This block is a reporter block.
Try This Computational Skills
Write the value of the following expressions taking the values of X, Y, and Z equal to 45, 20, and 15.
1. X mod Y ___________ 2. X / Y ___________
3. X > Y AND Y > Z ___________ 4. X < Y OR X > Z ___________
5. Y mod Z ___________ 6. NOT (X = Y) ___________
7. X / Z ___________ 8. X > Z AND Z > Y ___________
47