Scratch – Math Concepts: Online Course
Arithmetic Operations |
Now let’s take a look, arithmetic operators and functions that are supported in Scratch. If you want to calculation but currently you have no calculator, OK no problem. You can solve this problem using scratch. You can build your own calculator in Scratch with the blocks from the Operator Palette.
The Scratch supports the four basic arithmetic operations are addition, subtraction, multiplication, and division. The blocks used to perform these operations, called operators.
Scratch also supports the modulus (mod) operator, which returns the remainder of the division of two numbers. For example, 7mod 3 gives 1 because the remainder of 7 divided by 3 is 1.
The common arithmetic operators are:
Action | Common Symbol | Operator |
Addition | + | |
Subtraction | - | |
Multiplication | * | |
Division | / | |
Modulus (associated with integers) | % |
Note: Operators are the action elements of a computer program. operators operate on operands . The operands may be either constants or variables.
Example 1: Scratch Program to calculate Arithmetic Operator |
Scratch Program to calculate Arithmetic Operator using both number and variable.
Procedure: Let’s say the steps
- Click the Looks blocks.
- Drag the say() block to the script area from the looks Block Palette.
- Change text ‘hello!’ to ‘Enter Two Number‘. This text will appear small amount of time.
- Drag the basic math operator block for addition, subtraction and multiplication.
- Drop addition() block to say() block
- Adds the numbers that the operator contains
- After complete add process sprite color change
- Drag change() color for sprite
- Drag ask() block to the script area from the sensing Block Palette.
- Change text and asks the user to ‘Enter a number to subtract from 50′.
- Drop subtraction() block for number and variable for input value to say() block
- The subtraction operation performs this request using a number and a variable.
- Drag change() color for sprite
- Drag ask() block to the script area from the sensing Block Palette.
- Change text and asks the user to ‘Multiply two number’.
- The multiplication operation performs this request using a number and a variable.
- Drag change() color for sprite
- Add green flag block in starting for run the program.
- When the green flag is clicked, the script activates.
- To run the program. You should get the following result.
Input:
Output:
Example 2: Scratch Program to calculate Arithmetic Operator |
Scratch Program to calculate Arithmetic Operator using variable and set ().
Seven Variables
Seven variables identified for this scratch program. I will list them here:
- Num1 for Left operand
- Num2 for Right operand
- Sum for Addition
- Diff for Subtraction
- Mul for Multiplication
- Div for Division
- Mod for Modulus
Preparing the operator blocks
Scratch Program to calculate Arithmetic Operator
Procedure: Let’s say the steps
- Click the Variable blocks.
- First identify all variable for this Arithmetic Operator program
- In this Case we required a two operand and five operator variable.
- Click Make a variable and declare all variable name (for this sprite only)
- In this variable name for two operand (num1, num2) and five operator (Sum, Diff, Mul, Div and Mod).
- Then to set the specified variable for all the variables using set() block.
- Drag the set() block to the script area from the Variable Block Palette.
- Set variable for all two operand (Num1, Num2) for input value.
- Drag the set() for all the five operator variables with basic math block.
- Set variable for all the five operator variables. For example (set Sum variable with add block, set Diff variable with subtract block etc.).
- Add green flag block in starting for run the program.
- When the green flag is clicked, the script activates.
- To run the program. You should get the following result.
Input & Output of the program