Lesson 7 : Arithmetic Operators

Lesson Description

As of now, you’ve mastered sprites, backdrops, the Stage, drawing, animating, and creating variables. But PictoBlox is not just about drawing and animating; it’s much more than that. For starters, you can perform mathematical and logical operations using different Operators. In this lesson, students will be making an activity, an addition bot that takes two numbers and adds them.

What are Operators?

Operators are symbols that tell the computer to perform specific mathematical or logical manipulations. Following are the different types of operators in PictoBlox:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators

In this lesson, you’ll learn the arithmetic operators.

Arithmetic Operators

There are four main arithmetic operators in PictoBlox:

  1. Addition: Adds values on either side of the operator Addition
  2. Subtraction: Subtracts the right-hand operand from the left-hand operandSubtraction
  3. Multiplication: Multiplies values on either side of the operatorMultiplication
  4. Division: Divides the left-hand operand by the right-hand operanddivision
  5. Modulus (Remainder): Modulus operator (%) calculates the remainder when two variables are divided. Please note that this operation can only be performed on an integer.

Now, let’s perform an activity to see them in action.

 

In this activity, you’ve to make a script that:

  1. Asks the user to input Number 1.
  2. Asks the user to input Number 2.
  3. Performs addition operation on Number 1 and Number 2 and save the result in a variable answer.
  4. Display the answer to the user using a say () for () seconds block.

Addition of two numbers

Let’s Code

Follow the steps below:

  1. Open PictoBlox and create a New File.
  2. Select the coding environment as Block Coding.
  3. Add two ask () and wait blocks to get the input from users for Number 1 and Number 2. Using the ask () and wait block will add an input box (with the specified text above it) at the bottom of the Stage. The user can write the answer in it and submit it which is then stored then in the answer block.Making two variable join number
  4. Next, make 3 variables:
    1. Number 1: To store the value of the first input.
    2. Number 2: To store the value of the second input.
    3. Result: To store the final output value.
  5. Place two set () to () blocks, one below each ask () and wait block to store the input values in Number 1 and Number 2.Making two variable join number
  6. Place another set () to () block at the end and choose Result from its drop-down. Place a () + () block (addition operator block) in the white space and add Number 1 and Number 2.
  7. Make Tobi say the result out loud using the say () for () seconds block.
  8. Complete the script by adding a when flag clicked block.
  9. Save the file with the name Addition Bot.

Below is the complete script:Addition of two numbersAddition of two numbers

Assignment

Before you move on to the next lesson, a small assignment awaits you!

You must upload the PictoBlox program you created in this activity to the website. Submitting the assignment is a must in order to receive the certificate after completing the course.

Follow the steps below to upload your assignment:

  1. Click on Browse.
  2. Search and Select your saved Project file(.sb3) and Click Open.
  3. Click on Upload to submit the assignment.
evive Alert
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.

Good luck!

Table of Contents