Scratch – Math Concepts: Online Course
Comparison of Two Number |
Relational operators
Scratch has 3 operators that are used to relate two variables or two conditions with each other, meaning they are used to compare, hence it is also called comparison operator. This operator is used to check the relationship between two variables, constants or operands.
If we take the example of real life and explain to you about relational operator, then you will be able to understand very easily. For example, suppose there is a vacancy for any post in any company and for that minimum 60% marks are required in graduation, then here you will first compare 60% with your marks, which will be compared by relational operators only. e.g. 78% >= 60 %.
Note: The relational operator provides us only two values. 0 and 1. 0 means False i.e. the condition is wrong and 1 means True i.e. the condition is correct.
Scratch Program to Comparison two number |
Scratch Program to Comparison two number: To do this, we need to follow these steps
Step 1: All three relational operators are shown in the table given below, which can be used in scratch programming.
Operator | Name | Description |
Equal to | If two operands are equal then it returns True. | |
Greater Than | Returns True when the left operand is greater than the right operand. | |
Less Than | Returns True when the left operand is less than the right operand. |
Step 2: Less Than, Greater Than, Equal to
The three comparison symbols are less than (<), greater than (>) and equal to (=). The “equal to” symbol is used to represent two equal numbers or quantities, such as: 3 = 3 The “greater than” symbol is used to show if a number is greater than the other number. For example, 10 > 3 [10 is greater than 3] The “less than” symbol is used when a number or a quantity is less than the other. For example, 9 < 11 [9 is less than 11] |
Step 3: Procedure
- First Define Variable: two variables identified for this scratch program. I will list them here:
- ‘a’ variable for Left operand
- ‘b’ variable for Right operand
- From Events, Drag green flag() block on sprite area.
- Click on the “variables” tab (top left), and click “Make a variable”. Now type “a”, in the dialogue box.
- Repeat this, and create a ‘b’ variable.
- From Variables, Drag the set() block ‘set variable to 0’ Initialize ‘a’ variables to 0 (eg : my variable = s)
- To Replace 0 value from your value in set() block where variable is ‘a’
- Repeat this process for ‘b’ variable
- From control, drag ‘if-else block‘ and Drag ‘condition operator block‘ in the place of check condition option of ‘if-else block‘.
- From looks, Two time Drag say() block stays for the specified amount of time (inside the first C and inside the second C) of if-else condition.
- Let’s replace text value from condition text in both side.
- Repeat this process two time for (less than and equal to).
- When the green flag is clicked, the script activates.
- To run the program. You should get the following result.