ALGORITHMS WITH BLOCK CODING
how does he find that word 'proxy' in the
2.1 What will you learn in this
chapter?
Now that we already have a fair
understanding of coding applications in
real life, let us understand how to solve
a coding problem in detail. By the end of
this chapter, you will learn:
• What does the term algorithm
mean?
• What is a flowchart?
dictionary?
• Applications of flowchart
• Get introduced to pseudocode To achieve this, he first needs to find the
dictionary section with the first letter of
the word, which in this case is 'p.' Then,
2.2 Searching for a word in the within the list of words starting the first
dictionary letter 'p', he needs to find the section
having the second letter of the word 'r'.
While reading a book in a school library, He needs to do this operation again with
Mukesh comes across a word say 'proxy' the third, fourth & fifth letters until he
whose meaning he does not know. So finally reaches the word 'proxy' in the
how does he find out the meaning of this dictionary & then finds its meaning.
word? In other words, Mukesh needs to follow
The simple answer to this is that a set of steps to complete the task of
finding the meaning of a word.
Mukesh searches for the meaning of the
word 'proxy' in a dictionary. However, Similarly, before writing a program code
there are many words in a dictionary. So for a given problem in computer science,
6|Page
it is essential to devise a set of steps to
be followed to solve the problem
successfully. This set of steps is called
an algorithm.
Thus, in computer science, an algorithm
is defined as the step-by-step plan to
solve the problem for a given problem
statement.
2.3 Flowcharts
2.3.1 What is a Flowchart?
A flowchart is a diagrammatic
representation of the step-by-step plan
to be followed for solving a task/problem
statement.
This diagrammatic representation is
made up of shapes like boxes,
diamonds, parallelograms, circles,
ellipses connected by arrows. Each
shape acts as a step in the solution, and
the arrows represent the direction of
flow among the steps.
2.3.2 Symbols used in a flowchart
7|Page
2.3.3 Benefits of using a flowchart • The focus is mainly on including all
Some of the benefits of using a flowchart
are:
1. It helps to explain your approach
towards solving a problem
2. The flowchart helps in bringing in
visual clarity to a problem, so it
helps in practical problem solving
3. Once you build a flowchart, this
remains as documentation of the
code you are about to build. If you
need to come back and
understand the code, you can
refer to the flowchart.
2.4 Activity: Profit and loss
with flowcharts
the essential steps to solve the
Shown in the image is a flowchart that problem. Thus, the solution tends to
takes two inputs, namely cost price and be comprehensive
selling price. It then calculates profit or • Reviewers can quickly review the
loss depending on the values and prints pseudocode & verify if the steps will
the same. generate the desired outcome
• While writing pseudocode, you can
focus on all possible scenarios. So,
this helps you understand the
2.5 Pseudocode potential problems that might come
up later
2.5.1 What is a Pseudocode? • Since you are not worried about
coding syntax, you can concentrate
In computer science, pseudocode is on the actual problem
used to describe the steps followed in an • Writing pseudocode will help writing
algorithm via simple human- your code much easier
comprehensible language. Thus, it has • Works as documentation of the code.
no syntax of any programming language So even a layman with no coding
and can be understood by a layman. The knowledge can refer to the
advantages of representing the solution pseudocode
as pseudocode are multifold:
8|Page
2.6 Activity: Profit and loss programming and learn coding concepts
with pseudocode easily.
MakeCode Arcade is one of the platforms
to perform block-based programming.
Now that we have a fair understanding
of flowcharts and pseudocode, let us try Using arcade, solution to a problem
to implement the same profit and loss statement can be implemented using
problem using pseudocode. various categories of blocks and the
results can be seen side by side on the
same screen.
Program starts
The different categories of blocks will be
Read Cost Price (CP)
explored in the upcoming chapters.
Read Selling Price (SP)
Note: Minecraft is just one of the
If (SP > CP) then platforms for block coding. You can use
Profit = SP – CP many similar platforms available online
for block coding like – Scratch
Print Profit (https://scratch.mit.edu/), Code.org
Else (https://code.org/) etc.
Loss = CP – SP We will now start a simple block coding
exercise on Minecraft platform.
Print Loss
Open the URL
Program ends
https://arcade.makecode.com in your
favorite web browser.
2.7 Getting started with block
coding
Microsoft MakeCode is a framework for
creating interactive and engaging
programming experiences for those new
to the world of programming.
The main objective of MakeCode is to
bring programming to the forefront in a
way that is more alluring and friendly.
To achieve this, MakeCode utilizes the
blocks programming model to let those
who are new to the world of
9|Page
10 | P a g e
11 | P a g e
12 | P a g e
Congratulations, you have created your first block code program! Now let us do a quiz.
2.8 Quiz time
Objective type questions
1. Select a word from column A and place it in a cell on column B such that its
definition matches in cells of column C
A B C
Writing steps involved to
solve a problem in a
Algorithm
human-understandable
language
Block based coding
Flowchart
platform
Define step by step plan
Pseudo Code to solve a problem
statement
Solution to a problem
Arcade
presented as a diagram
Below is a flowchart to calculate profit and loss. Answer questions 2 to 4 based on the
flowchart.
13 | P a g e
Question 2 Jyoti owns a toy shop. She bought a toy for Rs 325 and sold it for Rs.
375. Which one from the below is correct?
Option 1 She made a loss of Rs. 50
Option 2 She made a profit of Rs. 50
Question 3 Raju buys a pen for Rs 15, and after some time, he sells it for Rs 10.
Which one from the below is correct?
Option 1 He made a loss of Rs. 5
Option 2 He made a profit of Rs. 5
Question 4 Ram buys a table for Rs 500, he sells it for Rs 550. Which one from
the below is correct?
Option 1 He made a loss of Rs. 50
Option 2 He made a profit of Rs. 50
14 | P a g e
Question 5 Which of the following is not an advantage of a flowchart?
Option 1 Efficient coding
Option 2 Systematic testing
Option 3 Improper documentation
Option 4 Better communication
Question 6 The following box denotes.
Option 1 Initialization
Option 2 Decision
Option 3 Input / Output
Option 4 Connectors
Question 7 What is a flowchart?
Option 1 A specific programming language
Option 2 A text-based way of designing an algorithm
Option 3 A bullet point list of instructions
Option 4 A diagram that represents a set of instructions
Question 8 What shape represents the start and end of a flowchart?
Option 1 Square
Option 2 Diamond
Option 3 Oval
Option 4 Circle
Short Answer questions
1. What is a pseudocode?
2. What are the benefits of using flowcharts?
3. What is a flowchart?
15 | P a g e
Higher Order Thinking Skills (HOTS)
1. Below is a flowchart on how to calculate if a number is even or odd. Write the
corresponding pseudocode for the problem.
Note: Modulus operator (%) is used to find the remainder of two number.
2. The below pseudocode prints "Above average marks" if the average marks in three
subjects are greater than 75. If average marks are less than or equal to 75, then
it prints "Below average marks". Draw the corresponding flowchart for the
problem.
16 | P a g e
Program starts
Read marks for subject SubA
Read marks for subject SubB
Read marks for subject SubC
Calculate AverageMarks = (SubA + SubB + SubC)/3
Print AverageMarks
If (AverageMarks > 75)
Print (“Above Average Marks”)
Else
Print (“Below Average Marks”)
Program ends
Applied Project
Create a flowchart based on your normal school day. Here are some guidelines:
Getting ready for school
• Look at your timetable and pack your school bag
• If PE is there packing your PE uniform and shoes
At school
• Attend the morning session with subjects Math, English and science
• A decision on what to play during recess
After reaching home
• Have snacks
• Depending on the day, choose the class you have to attend.
• Monday-Karate, Tuesday-Math Class, Wednesday and Thursday Free day,
Friday-Karate
17 | P a g e
2.9 What did you learn in this chapter?
• By now you should have a basic understanding about algorithms, flowchart
& pseudocode
• You have also practiced following a step by step approach to solve a problem
using block-based programming
• You got oriented to MakeCode platform which we will use throughout the
course
18 | P a g e