INTRODUCTION TO CODING
traffic signals to show different colors.
Sometimes it is even smarter, where the
1.1 What will you learn in this
code detects congestion based on
chapter? sensors and maximizes efficiency by
only functioning when traffic is present.
Do you want to know what code is? How
is code applied in real life, and how does 1.3 Where else do we see
it impact our day-to-day activities? applications of coding?
Welcome to the introductory section on
coding.
Most of us knowingly or unknowingly
Here you will learn:
engage with programming, be it inside
our homes or outside. Coding, in the
• Real world application of coding
modern world, can be seen on the
• How coding impacts our daily lives
streets, at the schools, at the local
• What exactly is coding in context
grocery stores, etc.
of computer science
Some of the practical examples of coding
in the real world are:
1.2 How do traffic lights work? • Interaction with bar-code
scanners at shopping store
• Automatic control of traffic using
Have you ever wondered traffic lights
how traffic signals • Booking movie, bus, train, flight
function? The lights cycle tickets online
through green, yellow, • Printers
and red at regular • Computer software we use like
intervals to control road web browser, Word etc.
intersections' traffic flow. They prevent • Video games and animations for
accidents and help to avoid congestion entertainment
on the roads.
However, how do the traffic lights 1.4 What exactly is coding?
change automatically?
Few lines of code running in the
Coding, also referred to as
background drive the traffic lights. At
programming, is creating instructions
regular intervals, the code changes the
that can be executed on a computer to
2|Page
perform a specific task or achieve a
particular result.
Coding is just like solving a math
problem. There may be many ways to
solve a problem. Similarly, there could
be more than one way to write
code for the same task. Just like solving
any other problem, some coding
approaches are more efficient than
others.
Think you are playing a video on your
smartphone. Your phone is like a
computer that needs to be instructed on
what to be done. The app playing the
video provides this instruction. This
video-playing app is an example of
coding. But how does the app
communicate the instructions to the Some of the most frequently used
phone? It does via a programming ones are:
language. In the next section, we will get
• Python
to know more about programming
• Java
languages. • JavaScript
• C#
1.5 What is a programming • R
• C++
language?
• C
• F#
Think about how we communicate with • COBOL
people around us? Language is our
primary means of communication for all Syntax is a set of rules that we need to
human interactions. Similarly, we can follow when we write a computer
interact with computers via a language program.
that computers understand. This
There are hundreds of programming
language is called a programming
language. Using programming languages used around the world. And
new ones are getting developed all the
languages, we can provide instructions
to a computer to perform a set of time. Every programming language has
activities. These sets of instructions are its own syntax. But all programming
languages have one common thing: they
also called programs. Like any other
language that has grammar, are eventually converted into a language
that the computer will understand.
programming languages have syntax.
3|Page
Throughout this chapter, we will learn know a little bit about coding and its
about different programming techniques applications, let us try to do some
and how to apply them. Now, that we exercises.
1.6 Quiz Time
Question 1 For a given problem, there is always only one way to write a program
Option 1 True
Option 2 False
Question 2 Pin authentication for ATM card transaction is an example of
programming
Option 1 True
Option 2 False
Question 3 Code is a set of instructions that can be executed on a computer to
perform a specific task
Option 1 True
Option 2 False
Question 4 Which among the below are examples of programming in real life?
Option 1 Robots
Option 2 Computer Games
Option 3 Self-drive cars
Option 4 All the above
Question 5 Which among the below is not an example of programming language?
Option 1 Python
Option 2 English
Option 3 JavaScript
4|Page
1.7 What did you learn in this chapter?
So, we are at the end of the introductory chapter for coding. By now, you should
understand
• How coding is being utilized in everyday life to perform complex tasks in an easy
manner
• What are the real-life applications of coding?
• What is exactly meant by the term coding in context of computer science?
• Now you know names of some of the most popular programming languages
5|Page
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