To Coding: Grade Vi Teacher Handbook
To Coding: Grade Vi Teacher Handbook
TO CODING
GRADE VI
Teacher Handbook
Version 1.0
INTRODUCTION
TO CODING
GRADE VI
Teacher Handbook
ACKNOWLEDGEMENT
Patrons
• Sh. Ramesh Pokhriyal 'Nishank', Minister of Human Resource Development,
Government of India
• Sh. Dhotre Sanjay Shamrao, Minister of State for Human Resource
Development, Government of India
• Ms. Anita Karwal, IAS, Secretary, Department of School Education and Literacy,
Ministry Human Resource Development, Government of India Advisory
Coding is a creative activity that students from any discipline can engage in. It helps to
build computational thinking, develop problem solving skills, improve critical thinking
and exposure to real life situations to solve problems in various realms.
CBSE acknowledges the initiative by Microsoft India in developing this coding handbook
for class VI teachers. This handbook introduces concepts of coding and computational
thinking using real life examples and block coding with open source MakeCode platform.
It uses gamified learning approach to make learning experience more engaging. The
book is intuitive with practical examples of theoretical concepts and applied exercises.
There are mini projects that students can work on. Additionally, the handbook also
focuses on creating exposure to ethics of coding and promotes empathy among students
by activities curated to demonstrate empathy and sensitivity.
The purpose of the book is to enable the future workforce to acquire coding skills early
in their educational phase and build a solid foundation to be industry ready.
RESOURCES FOR STUDENTS
MakeCode
Microsoft MakeCode is a free, open source platform for creating engaging computer
science learning experiences that support a progression path into real-world
programming. It brings programming to life for all students with fun projects, immediate
results, and includes both block and text editors for learners at different levels. Visit
https://www.microsoft.com/en-us/makecode for more details.
GitHub
GitHub is a storehouse where you can manage and collaborate on your code. It helps to
maintain different versions of the code easily. GitHub Student Developer Pack gives
students free access to the best developer, web development, gaming and many other
tools at no cost enabling practical learning.
Sign up for the GitHub Student developer pack here
https://education.github.com/discount_requests/student_application?utm_source=2
021-06-11-cbse
TABLE OF CONTENTS
Table of Contents ........................................................................................... I
Ethical practices in coding ...............................................................................1
Introduction to Coding ....................................................................................2
1.1 Lesson Structure ................................................................................2
1.2 Lesson Plan .......................................................................................2
1.2.1 Teacher’s Notes .............................................................................2
1.3 What will you learn in this chapter? .......................................................3
1.4 How do traffic lights work?....................................................................3
1.5 Where else do we see applications of coding?............................................3
1.6 What exactly is coding? ........................................................................3
1.7 What is a programming language?..........................................................4
1.8 Quiz Time ..........................................................................................5
1.9 What did you learn in this chapter? ........................................................5
Algorithms With Block Coding ..........................................................................6
2.1 Lesson Structure ................................................................................6
2.2 Lesson Plan .......................................................................................6
2.2.1 Teacher’s Notes .............................................................................7
2.3 What will you learn in this chapter? .......................................................8
2.4 Searching for a word in the dictionary.....................................................8
2.5 Flowcharts .........................................................................................8
2.5.1 What is a Flowchart?......................................................................8
2.5.2 Symbols used in a flowchart ............................................................9
2.5.3 Benefits of using a flowchart............................................................9
2.6 Activity: Profit and loss with flowcharts ................................................. 10
2.7 What is a Pseudocode? ....................................................................... 10
2.8 Activity: Profit and loss with pseudocode ............................................... 10
2.9 Getting started with block coding ......................................................... 11
2.10 Quiz time ...................................................................................... 14
2.11 What did you learn in this chapter? ................................................... 19
I
................................................................................................................. 20
Variables using block coding .......................................................................... 20
3.1 Lesson Structure .............................................................................. 20
3.2 Lesson Plan ..................................................................................... 20
3.2.1 Teacher’s Notes ........................................................................... 20
3.3 What will you learn in this chapter? ..................................................... 21
3.4 What are variables? ........................................................................... 21
3.5 Naming variables .............................................................................. 21
3.6 Data types in variables....................................................................... 21
3.7 Performing Operations on Variables...................................................... 24
3.8 Activity: Addition operation using block coding ....................................... 25
3.9 Quiz time......................................................................................... 32
3.10 What did you learn in this chapter? ................................................... 35
Control with conditionals............................................................................... 36
4.1 Lesson Structure .............................................................................. 36
4.2 Lesson Plan ..................................................................................... 36
4.2.1 Teacher’s Notes ........................................................................... 37
4.3 What will you learn in this chapter? ..................................................... 38
4.4 Arranging blocks............................................................................... 38
4.5 And operator .................................................................................... 38
4.6 OR Operator..................................................................................... 39
4.7 NOT Operator................................................................................... 39
4.8 Combining logical operators ................................................................ 40
4.9 Quiz time......................................................................................... 41
4.10 Relational operators........................................................................ 42
4.11 Activity: Are you a teen? .................................................................. 42
4.12 Activity: Dynamic backgrounds......................................................... 42
4.13 Nested Conditional Statements ......................................................... 48
4.14 Activity: The remainder problem........................................................ 48
4.15 Quiz time ...................................................................................... 52
4.16 What did you learn in this chapter? ................................................... 55
II
Loops using block coding............................................................................... 56
5.1 Lesson Structure .............................................................................. 56
5.2 Lesson Plan ..................................................................................... 56
5.2.1 Teacher’s Notes ........................................................................... 56
5.3 What will you learn in this chapter? ..................................................... 57
5.4 Introduction to loops ......................................................................... 57
5.5 Increment Loops ............................................................................... 57
5.6 Different types of loops....................................................................... 58
5.7 Activity: Building a music player .......................................................... 61
5.8 Entry Criteria ................................................................................... 64
5.9 Exit Criteria ..................................................................................... 64
5.10 Break Statement ............................................................................ 64
5.11 Continue Statement ........................................................................ 65
5.12 Activity: A tale of two villages............................................................ 66
5.13 Quiz time ...................................................................................... 71
5.14 What did you learn in this chapter? ................................................... 74
References .................................................................................................. 75
III
Ethical practices in coding
• You must limit negative results of software, including dangers to safety, health,
personal security, and privacy
• Do consider the aftereffects of the software. Ensure your Code respects diversity
and is utilized responsibly with social issues in mind
• In addition to this, promote environmental sustainability both locally and globally
Avoid harm to others
• Your code should not cause physical or mental injury, unjustified destruction to
property or information
• Avoid unjustified damage to reputation and environment
1|Page
Introduction to Coding
INTRODUCTION TO CODING
2|Page
Introduction to Coding
1.3 What will you learn in sensors and maximizes efficiency by
this chapter? only functioning when traffic is present.
3|Page
Introduction to Coding
code for the same task. Just like solving
any other problem, some coding
approaches are more efficient than
others.
4|Page
Introduction to Coding
Question 1 For a given problem, there is always only one way to write a program
Option 1 True
Option 2 False
Answer: Option 2
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
Answer: Option 4
Option 1 Python
Option 2 English
Option 3 JavaScript
Answer: Option
• 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
6|Page
Algorithms With Block Coding
The teacher should introduce pseudocode to the students by using real-life examples like
those mentioned in the curriculum. They should make sure that the children are not
confused with these terms and explain the pseudo code to the students to improve their
conceptual understanding
Activity: Place students in groups of three or four and guide them through the
exercises
For the exercise section, the teacher should make sure that the children are comfortable
with the Make Code platform and they have it working on their computers. The practice
challenges can be solved in several ways and do not have a definite answer.
Assignment: Allow students to perform at least one practice exercise on their own
The teacher should encourage students to come up with unique solutions to the challenges
to test their creativity and understanding of the subject.
7|Page
Algorithms With Block Coding
In other words, Mukesh needs to follow
2.3 What will you learn in a set of steps to complete the task of
this chapter? finding the meaning of a word.
Similarly, before writing a program code
Now that we already have a fair for a given problem in computer science,
understanding of coding applications in it is essential to devise a set of steps to
real life, let us understand how to solve be followed to solve the problem
a coding problem in detail. By the end of successfully. This set of steps is called
this chapter, you will learn: an algorithm.
8|Page
Algorithms With Block Coding
2.5.2 Symbols used in a flowchart
9|Page
Algorithms With Block Coding
• The focus is mainly on including all
the essential steps to solve the
2.6 Activity: Profit and loss
problem. Thus, the solution tends to
with flowcharts be comprehensive
• Reviewers can quickly review the
Shown in the image is a flowchart that pseudocode & verify if the steps will
takes two inputs, namely cost price and generate the desired outcome
selling price. It then calculates profit or • While writing pseudocode, you can
loss depending on the values and prints focus on all possible scenarios. So,
the same. this helps you understand the
potential problems that might come
up later
• Since you are not worried about
coding syntax, you can concentrate
on the actual problem
• Writing pseudocode will help writing
your code much easier
• Works as documentation of the code.
So even a layman with no coding
knowledge can refer to the
pseudocode
10 | P a g e
Algorithms With Block Coding
The different categories of blocks will be
explored in the upcoming chapters.
Program starts
Note: Minecraft is just one of the
Read Cost Price (CP) platforms for block coding. You can use
many similar platforms available online
Read Selling Price (SP)
for block coding like – Scratch
If (SP > CP) then (https://scratch.mit.edu/), Code.org
(https://code.org/) etc.
Profit = SP – CP
We will now start a simple block coding
Print Profit
exercise on Minecraft platform.
Else
Open the URL
Loss = CP – SP https://arcade.makecode.com in your
Print Loss favorite web browser.
Program ends
11 | P a g e
Algorithms With Block Coding
12 | P a g e
Algorithms With Block Coding
Congratulations, you have created your first block code program! Now let us do a quiz.
13 | P a g e
Algorithms With Block Coding
2.10 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
Solution to a problem
Arcade
presented as a diagram
Answer:
A B C
Pseudo Code Writing steps involved to
solve a problem in a
Algorithm
human-understandable
language
Arcade
Block based coding
Flowchart
platform
Flowchart
Solution to a problem
Arcade
presented as a diagram
14 | P a g e
Algorithms With Block Coding
Below is a flowchart to calculate profit and loss. Answer questions 2 to 4 based on the
flowchart.
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
Answer: Option 2
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
Answer: Option 1
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
Answer: Option 2
15 | P a g e
Algorithms With Block Coding
Option 1 Initialization
Option 2 Decision
Option 3 Input / Output
Option 4 Connectors
Answer: Option 2
Option 1 Square
Option 2 Diamond
Option 3 Oval
Option 4 Circle
Answer: Option 3
16 | P a g e
Algorithms With Block Coding
Note: Modulus operator (%) is used to find the remainder of two number.
Teacher’s Note: The teacher should explain to the students the above flowchart to
understand it and write the corresponding pseudocode. The teacher should
encourage the students to do the problem on their own.
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.
17 | P a g e
Algorithms With Block Coding
Program starts
Print AverageMarks
Program ends
Teacher’s Note: The teacher should explain to the students the above pseudocode
to understand it and write the corresponding flowchart. The teacher should
encourage the students to do the problem on their own.
Applied Project
Create a flowchart based on your normal school day. Here are some guidelines:
Getting ready for 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
Teacher’s Note: The teacher should explain to the students the project to understand it
and write the corresponding flowchart for their daily routine. The teacher should
encourage the students to do the problem on their own. The flowcharts will be different
for all the students.
18 | P a g e
Algorithms With Block Coding
2.11 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
19 | P a g e
Variables using block coding
20 | P a g e
Variables using block coding
3.3 What will you learn in variables uniquely, user needs to
this chapter? allocate them a unique name. This name
acts as an identifier for that variable. In
programming, a user is not allowed to
• What are variables? use the same name of a variable more
• How to name variables? than once.
• Commonly used data types
• Performing operations on variables Naming variables make it to easier to call
them while performing operations. The
name of a variable also suggests what
3.4 What are variables? information the variable contains.
You can refer to the example before for
In programming, variable is a packet in better understanding about variables:
which we can store data. These packets If variable named as "a" is equal to 2 and
can be named and referenced and can be variable named as "b" is equal to 2,
used to perform various operations. To performing add operation on "a" and "b"
perform a mathematical operation, you
is going to result into an output as "4".
can declare two variables and perform
the operation on them.
3.6 Data types in variables
Scope of a variable refers to the part of
the code where the variable can be used.
The scope or accessibility of the Variables are the values that are acted
variables defined in a program depends upon. Every value needs to be assigned
on where you have declared it in each to a specific data type to make the
program. Any defined variable cannot be variable more readable by a computer.
accessed beyond its scope. Data type identifies what the type of data
that the declared variable can hold is.
Thus, it indirectly helps the computer to
3.5 Naming variables understand what operations need to be
performed on those variables. The
21 | P a g e
Variables using block coding
contains two components – the name of language, the syntax to declare floating-
the variable and its type. point variable changes.
22 | P a g e
Variables using block coding
data type is present to fit the gap. The z = int(7)
String data type stores value in a
a = float(7)
sequence of characters i.e. in String
format. y will be saved as ‘7’
Any string value can be declared as a z will be saved as 7
string variable.
a will be saved as 7.0
Boolean Data Type
Let us now apply different data types in
There is a subtype of Integer Data Type a pseudocode. We will first declare
called "Boolean Data Type", which stores different types of variables, followed by
values in Boolean type only i.e. "true" or assigning them to appropriate values.
"false". Users can choose between the
data types for variables as per program Function Main
needs and assign variables an Declare
appropriate data type.
----------------------------------------------------------
Boolean is a subtype of integer data
Declare Integer i
type. It stores true and false where true
means non-zero and false means zero. Declare Float f
23 | P a g e
Variables using block coding
Finally, we will use the variables by Arithmetic Operations
outputting their values.
Int i = 1234567890
Float f = 1.234
Char c = c
String s = string
Boolean b = true
24 | P a g e
Variables using block coding
variable on right from the current Example: A=8
value on the left.
B=A--
Example: : x -= y
It can also be written as x = x - y The output of B will be 7 (A-1)
• “*=”: This operator assigns the
result to the variable on the left A-- has the same meaning as A=A-1
after multiplying the current
value of the variable on left to the 3.8 Activity: Addition
value on the right. operation using block
Example: : x *= y
coding
It can also be written as x = x * y
• “/=”: This operator assigns the
result to the variable on the left An addition arithmetic operation is used
after dividing the current value of to add the values stored in two variables.
the variable on left from the value Like the way we add values in
on the right. mathematics, we can store values in
Example: : x /= y different variables and perform an
additional operation. The addition of
It can also be written as x = x / y
these variables is displayed as an output
Increment operator of the program.
Increment operator adds one to the For example, performing add operation
value. on a variable "a" holding value "3" and a
variable "b" holding value "4" will result
Example: A=8 in an output "7".
B=A++ To understand this arithmetic operation
The output of B will be 9 (A+1) better, let us understand how to
implement it practically in
A++ has the same meaning as A=A+1 programming. For this, we are going to
take example of platform -
Decrement operator
https://arcade.makecode.com/. Let us
Decrement operator subtracts one from refer to the steps below understand
the value. more in details.
25 | P a g e
Variables using block coding
26 | P a g e
Variables using block coding
27 | P a g e
Variables using block coding
28 | P a g e
Variables using block coding
29 | P a g e
Variables using block coding
30 | P a g e
Variables using block coding
31 | P a g e
Variables using block coding
Subtraction Division
Subtraction arithmetic operation is used Division arithmetic operation is used to
to subtract the values stored in one divide the value stored in one variable by
variable from another variable. Like the the value stored in another variable. Like
way we subtract values in mathematics, the way we divide values in
we can store values in different variables mathematics, we can store values in
and perform subtraction operations. different variables and perform division
Subtraction of these variables is operations. Division of these variables is
displayed as an output of the program. displayed as an output of the program.
32 | P a g e
Variables using block coding
Option 1 _test
Option 2 11test
Option 3 Test13
Option 4 Test_2
Answer: Option 2
Option 1 Sum,+
Option 2 Var,-
Option 3 Bool,+
Option 4 Add,+
Answer: Option 1
Question 5 Which of the following data type is used to store decimal values?
Option 1 Integer
Option 2 Float
Option 3 Boolean
Option 4 String
Answer: Option 2
Question 6 How many times should a data type be mentioned for a variable
Option 1 *
Option 2 +
Option 3 x
Option 4 %
Answer: Option 1
33 | P a g e
Variables using block coding
Question 8 What is the alternative of y=y+9
Option 1 y=x+9
Option 2 y+=9
Option 3 y-=9
Option 4 x=+9
Answer: Option 2
Option 1 Y=Y+1
Option 2 X=+2
Option 3 y-=6
Option 4 X=x-5
Answer: Option 1
Option 1 *
Option 2 +
Option 3 x
Option 4 %
Answer: Option
34 | P a g e
Variables using block codingControl with conditionalsVariables
using block codingVariables using block coding
2. Create a project in https://arcade.makecode.com/ to perform Modulus operation
on two variables in a program.
Teacher’s Note: The teacher should explain modulus operation to the students and
encourage them to write the pseudocode and then create the block code project for
two variables.
Applied Project
Using block coding, create your normal school day (Monday to Friday).
Here are some guidelines:
• Attend the morning session with subjects Math, English and science
• A decision on what to play during recess
• Attend the afternoon session subjects
• Lunch Break
• PE Class
After reaching home
• Have snacks
• Depending on the day choose the class you must attend.
Monday-Karate, Tuesday-Math Class, Wednesday-Swimming and Thursday-
Chess, Friday-Dance (You can use variables to define the class you have to
attend)
35 | P a g e
Control with conditionals
Relational Operators
36 | P a g e
Control with conditionals
4.2.1 Teacher’s Notes
Discuss: What are logical operators in real life?
The teacher should introduce logical operations to the students by using real -life
examples like those mentioned in the curriculum. They can also ask the students to
come up with such examples to encourage critical thinking.
Combining operators should be explained with the flowcharts provide d. The teacher can
also ask students to draw a few flowcharts on their own to test their understanding.
Students might be familiar with relational operators already, so using them in examples
and pseudo code should be helpful.
Activity: Place students in groups of three or four and guide them through the
exercises
For the exercise section, the teacher should make sure that the children are comfortable
with the Make Code platform and they have it working on their computers. The practice
challenges can be solved in several ways and do not have a definite answer.
Assignment: Allow students to perform at least one practice exercise on their
own
The teacher should encourage students to come up with unique solutions to the
challenges in order to test their creativity and understanding of the subject.
37 | P a g e
Control with conditionals
In the earlier chapters, we discussed
how to handle decisions in a flow chart.
4.3 What will you learn in
Now we shall see how to implement it in
this chapter? our code.
• What are conditions and how to We can do things conditionally in our
apply them in real life? programs using if statements or if/else
• What are the different types of
statements combined with logical
operators?
• How to combine multiple operators. Logical operators work like
operators? Boolean variables and return either
• Apply logical operations in block TRUE or FALSE.
coding
The three most important logical
operators are AND, OR and NOT.
Logical
In the image below, we see several blocks operators
arranged in a specific order. Every time
we place a new block, we apply logic to
build a diagonal line with blocks marked
with arrows. This logic in coding terms AND OR NOT
are called conditions.
38 | P a g e
Control with conditionals
And the decision we are deriving is: Like the previous example, if we want to
derive the logical operation from this
Decision: Should you go to bed?
scenario, we have the following
Based on this we can write the below conditions:
pseudo code:
Condition 1: Is it sunny outside?
IF (Homework completed) AND (Time is past Condition 2: Is it raining outside?
8 PM)
THEN And the decision we are deriving is:
Go to bed
ELSE Decision: Should we carry an umbrella?
Do not go to bed
END The pseudocode for this will look like
below:
Let us now try to see the different IF (It is sunny outside) OR (It is raining
combinations possible with the above outside)
pseudo code. THEN
Carry an umbrella
Condition 1 Condition 2 Decision ELSE
Have you Is the time Should Do not carry an umbrella
completed past 8 PM? you go to END
homework? bed?
Yes Yes Yes Shown below are the different possible
No Yes No combinations for the above example.
Yes No No
No No No Condition 1 Condition 2 Decision
Is sunny? Is raining? Carry
umbrella?
Having this example in mind, let us now Yes Yes Yes
see how this is different from OR Yes No Yes
operator. No Yes Yes
No No No
4.6 OR Operator
Let us now look at the NOT operator.
39 | P a g e
Control with conditionals
Unlike the previous examples, here we
have only one condition.
Condition: Is it raining?
Decision: Go out to play?
40 | P a g e
Control with conditionals
Question 1
Situation Today is Tuesday, and the time is 4 PM. Is the library open now?
Option 1 Yes
Option 2 No
Answer: Option 2
Question 2
Situation Today is Monday and the time being 10.30 AM. Is the library open
now?
Option 1 Yes
Option 2 No
Answer: Option 1
Question 3
Situation Today is Friday, and the time is 12 PM. Is the library open now?
Option 1 Yes
Option 2 No
Answer: Option 2
Question 4
Situation Today is Wednesday, and the time is 10.30 AM. Is the library open
now?
Option 1 Yes
Option 2 No
Answer: Option 2
Question 5
Situation Today is Wednesday and the time is 3.30 PM. Is the library open
now?
Option 1 Yes
Option 2 No
Answer: Option 1
41 | P a g e
Control with conditionals
If age>19 then adult
• Print “child or teenager or adult”
4.10 Relational operators
depending on the condition
satisfied
In our previous example, we got
introduced to some relational operators
like greater than equals (>=), equals (==),
and less than equals (<=).
Let us now look at the full list of
relational operators.
42 | P a g e
Control with conditionals
To access the MakeCode editor, open your favorite browser and go to
https://arcade.makecode.com/. Create a new project as shown below.
Now follow the below steps to see how we can use conditionals in block coding.
43 | P a g e
Control with conditionals
44 | P a g e
Control with conditionals
45 | P a g e
Control with conditionals
46 | P a g e
Control with conditionals
When you change the height to 10 the loop will go inside the if condition as the height
is greater than 5 AND less than 20. The background color will change to green.
So, what did we learn from this That is correct! The background color
activity? change to green as height is greater than
5 AND less than 20.
You have now learnt how to create
conditional statements. What do you
think will the output of the code be if you
change the height to 15?
47 | P a g e
Control with conditionals
4.13 Nested Conditional 4.14 Activity: The
Statements remainder problem
48 | P a g e
Control with conditionals
49 | P a g e
Control with conditionals
50 | P a g e
Control with conditionals
51 | P a g e
Control with conditionals
Question 1 Today is Monday and time is 11.30 AM. Is today a school day?
Option 1 True
Option 2 False
Answer: Option 1
Question 3 Today is Wednesday and time is 5.30 AM. Is today a school day?
Option 1 True
Option 2 False
Answer: Option 1
Question 4 Today is Sunday and the time is 09.30 PM. Is today a Holiday?
Option 1 True
Option 2 False
Answer: Option 2
52 | P a g e
Control with conditionals
Question 6 Which operator is used if the statement evaluates true only if both
the expressions are true
Option 1 And
Option 2 Or
Option 3 Not
Option 4 None of the above
Answer: Option 1
Question 7 Which operator is used if the statement evaluates true only if only
one of the expressions is true
Option 1 And
Option 2 Or
Option 3 Not
Option 4 None of the above
Answer: Option 2
Option 1 Child
Option 2 Teenager
Option 3 Adult
Option 4 None of the above
Answer: Option 3
Question 10 Your sister’s age is 19. In which category will she fall?
Option 1 Child
Option 2 Teenager
Option 3 Adult
Option 4 None of the above
Answer: Option 2
53 | P a g e
Control with conditionals
Short Answer Questions
1. What are the different types of logical operators? Explain with examples.
2. Explain with example on how to combine different logical operators.
3. Write the pseudocode using logical operators to decide if today is a school day or
not.
(Monday-Friday: School day;
Sunday: Holiday;
1st and 3rd Saturday: Holiday;
2nd and 4th Saturday: School day)
Applied Project
Create a program using conditional statements for a sports event. If an event occurs,
THEN what happens?
Here are some guidelines:
54 | P a g e
Control with conditionals
Teacher’s Note: The teacher should explain the student’s questions first so that the
students can understand it and write the corresponding block code/Pseudocode for the
questions. The teacher should encourage the students to do the problem by their own.
For the nested if block the students can form groups to solve the problem and come up
with a solution together.
• You should now have an understanding on the AND, OR, NOT logical operators.
• You can now combine different logical operators.
• You have understood how to apply logical operators in block coding.
• Understand nested conditional statement in block coding.
55 | P a g e
Loops using block coding
Assignment 1 Practical
56 | P a g e
Loops using block coding
5.3 What will you learn in
this chapter? This was easy. Now consider a
requirement where you we need to print
numbers in incremental order from 1 to
• What are loops? 1000. Although it is possible to print it
• How to increment loops? following the above pseudocode, it will
• Different types of loops get a very tedious and lengthy process.
• Concept of nested loops This is where loops come into the picture
to make this task easier. You can use the
concept of loops and get the desired
output by writing just a few lines of code.
5.4 Introduction to loops
57 | P a g e
Loops using block coding
mind while programming that the
condition should result false at a certain
point in time. Otherwise, this block of
code will enter an infinite loop.
58 | P a g e
Loops using block coding
The While loop can execute a set of I will eat healthy food every day.
commands till the condition is true I will eat healthy food every day.
While Loops are also called conditional I will eat healthy food every day.
loops.
Once the condition is met then the loop
is finished. Let’s now see a few examples: Example 3 - Print a statement 3 times
after that print different statement.
Example 1 – Print number from 1 to 15
Condition: Till the time the test
Here, if we want to derive the loop from expression remains true we will run the
this scenario, we have the following body of while loop printing statement 1
conditions: and after the condition is false, we will
print statement 2.
Condition: Write from 1 to 15
And the decision we are deriving is:
And the decision we are deriving is:
Decision: Have we printed the
Decision: Have we reached 15 statement 1 three times, if yes then print
Based on this we can write the below the statement 2
pseudocode: Based on this we can write the below
pseudocode:
y=0
while y < 15
y=0
y+=1 while y < 3
print(y) y+=1
print(“Please,”)
else
Example 2 - Print a statement 3 times print(“I want to play.”)
using while loop.
Condition: Till the time the test This is the result for the code
expression remains true we will run the
body of while loop Please,
Please,
And the decision we are deriving is:
Please,
Decision: Have we printed the I want to play.
statement 3 times
Based on this we can write the below Example 4 - Print number from 10 to 1
pseudocode: Condition: Till the time the test
expression remains true we will run the
y=0 body of while loop printing statement
while y < 3 and after the condition is false the loop
y+=1 will stop
print(“I will eat healthy food every day.”)
And the decision we are deriving is:
59 | P a g e
Loops using block coding
Decision: Have we printed 1 I will study every day.
Based on this we can write the below I will study every day.
I will study every day.
pseudocode:
I will study every day.
I will study every day.
x = 10
while x==1
print(x) Example 2 – Use for loop to print all the
x-=1 odd numbers from a list.
The pseudo code for this will look like
This is the result for the code below:
For loop is needed for iterating over a The pseudo code for this will look like
sequence. A for loop executes for a below:
specific number of times.
list2 = [13, 24, 7, 49, 74, 29]
Now let us see a few examples: for x in list2:
if x % 2 == 0:
Example 1 – We need to print a print(x, end = " ")
statement five times using the for loop
The pseudo code for this will look like
below: This is the result for the code
for i in range(5) 24 74
print(“I will study every day.”)
i++
60 | P a g e
Loops using block coding
completion. This combination of loops
inside loop is helpful while working with
requirements where user wants to work
of multiple conditions simultaneously.
There is no restriction on how many
loops can be nested inside a loop.
61 | P a g e
Loops using block coding
62 | P a g e
Loops using block coding
When you click on the play for the above The flow starts with 1 and in each
exercise that we created, you will hear iteration, it increments once. Each time
the music 10 times. The loop repeats loop completes once iteration, and you
itself 10 times (counter that we had set). will hear music once.
63 | P a g e
Loops using block coding
5.8 Entry Criteria while defining a loop. As without an exit
criterion, the program tends to enter in
an infinite loop. These criteria differ from
Now that we have understood about program to program as per the
different loops and its iterations, it is requirement.
also important to understand when and
where should one start iterating through For example, while creating a loop to
these loops. When the looping condition print numbers from 1 to 1000, exit
is true then the code will enter a loop. it criteria is that loop should exit the block
is important to define an entry criterion of code when the 1000th number is
for the loop to ensure that the loop runs. printed, else the program will enter an
infinite loop.
Entry criteria is defined as a condition
that must be met before starting a
specific task. It is a set of conditions that
must exist before you can start a task. 5.10 Break Statement
These criteria differ from program to
program as per the requirement.
The break statement modifies the
For example, To start a car you need normal flow of execution while it
petrol/diesel. If your fuel tank is empty terminates the existing loop and
your car won’t start. So, the entry continues execution of the statement
criteria for the car to start is fuel tank following that loop. Break statement is
should not be empty. required as sometimes you want to
break out of a loop early when a
5.9 Exit Criteria condition is met.
64 | P a g e
Loops using block coding
As we see the control skips the lines force the next iteration and skip some
after the break statement and executes lines of code within the loop.
the first statement outside the loop.
Let us now understand continue
Example – Use break statement to statements with the below pseudocode:
print number from 9 to 5 and another
print statement when you encounter
break
a=9
while a > 0:
print 'Current variable is :', a
a = a -1
if a == 5:
break
print "Bye!"
This is the result for the code As you can see, as soon as the continue
statement is encountered, the lines
Current variable is :9 below the continue statement are
Current variable is :8 skipped. But unlike the break
Current variable is :7 statement, the loop is not terminated.
Current variable is :6 Instead, the control jumps to the
Bye! beginning of the loop.
65 | P a g e
Loops using block coding
Current variable is :9
Current variable is :8
Current variable is :7
Current variable is :6
Current variable is :4
Current variable is :3
Current variable is :2
Current variable is :1
Current variable is :0
Bye!
66 | P a g e
Loops using block coding
67 | P a g e
Loops using block coding
68 | P a g e
Loops using block coding
There are many other challenges that can be done. Let us do one more to help villagers
learn how to farm.
69 | P a g e
Loops using block coding
70 | P a g e
Loops using block coding
71 | P a g e
Loops using block coding
Question 8 Doing something over and over again or repeating code is called as
Option 1 Code
Option 2 loop
Option 3 Program
Option 4 Bug
Answer: Option 2
count = 0;
sum = 0;
count = count + 1;
}
print sum;
Answer: Option 1
Question 11 Which letter won’t print while running the below pseudocode?
Option 1 ‘d’
Option 2 ‘c’
Option 3 ‘n’
Option 4 ‘o’
72 | P a g e
Loops using block coding
if letter == "i":
break
print(letter)
print("End")
Answer: Option 3
Question 12 Which letter won’t print while running the below pseudocode?
Option 1 ‘g’
Option 2 ‘o’
Option 3 ‘d’
Option 4 ‘i’
if letter == "i":
continue
print(letter)
print("End")
Answer: Option 4
73 | P a g e
Loops using block coding
Higher Order Thinking Skills (HOTS)
Now that you know the concept of Nested Loops. Using Arcade MakeCode platform
create an example for nested loops.
Teacher’s Note: The teacher should explain to the students regarding nested loops. The
teacher should encourage the students to do the problem independently and come with
different examples. For the nested block, the students can form groups to solve the
problem and come up with a solution together.
Applied Project
Write a program using loops that ask the user to enter an even number. If the number
entered does not display an appropriate message and asks them to enter a number
again. Do not stop until an even number is entered. Print a congratulatory message at
end.
Teacher’s Note: The teacher should encourage the students to form groups or to do the
problem by their own.
• You should now have an idea of what are loops and how they are used in
programming?
• Incrementing loops
• Different types of loops
• What is entry and exit criteria in loops and its usage?
• Break and continue statements
• Concept of nested loops
74 | P a g e
References
REFERENCES
Microsoft. 2021. Microsoft MakeCode for Minecraft. [Online]. [25 February 2021].
Available from: https://minecraft.makecode.com
Microsoft. 2020. Activity: We Built a Zoo. [Online]. [25 February 2021]. Available
from: https://education.minecraft.net/class-resources/computer-science-subject-
kit
ACM, Inc. 2021. Code of Ethics. [Online]. [25 February 2021]. Available from:
https://www.acm.org/code-of-ethics
Microsoft. 2020. Hour Of Code 2020 | Minecraft: Education Edition. [Online]. [25
February 2021]. Available from: https://education.minecraft.net/hour-of-code-
2020
75 | P a g e