Lesson 1, Topic 1
In Progress

Activity 1: Check Perfect Squares

A perfect square is a number that can be expressed as the product of an integer by itself. Like 9, 25, 100, etc.

Let’s look at the flowchart to identify if a number is a perfect square or not:

Let’s take the example for 9.

  1. Loop 1:
    1. Count = 1
    2. Square = 1
    3. Square < 9 – Restart the loop
  2. Loop 2:
    1. Count = 2
    2. Square = 4
    3. Square < 9 – Restart the loop
  3. Loop 3:
    1. Count = 3
    2. Square = 9
    3. Perfect Square

Let’s take another example for 12.

  1. Loop 1:
    1. Count = 1
    2. Square = 1
    3. Square < 12 – Restart the loop
  2. Loop 2:
    1. Count = 2
    2. Square = 4
    3. Square < 12 – Restart the loop
  3. Loop 3:
    1. Count = 3
    2. Square = 9
    3. Square < 12 – Restart the loop
  4. Loop 4:
    1. Count = 4
    2. Square = 16
    3. Square > 12 – Not a perfect Square

Code

Let’s write the code for the flowchart.

  1. Create three variables:
    1. Number: To store the number we are checking for a perfect square.
    2. Count: To keep track of loop counts
    3. Square: To calculate the square in the loop.
  2. Get the Number from the user, using ask and wait block.
  3. Set Count to 1.
  4. Add the repeat () block and add round (Number /2) in the condition.
  5. In the loop, set the Square as Count * Count.
  6. Now add an if () block and check if Number = Square. If yes display the message and stop the program with stop () block from the Control palette.
  7. Next, add another if () block and check if NumberSquare. If yes display the message and stop the program with stop () block from the Control palette.
  8. Finally, add change (Count) by 1 below the last if () block.

Your script is complete.

Click the green flag to check the code.

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 Choose File.
  2. Select the image from the pop-up window that opens up.
  3. Once the image is selected, click on Upload 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!