ClassVIII Coding Teacher Handbook
ClassVIII Coding Teacher Handbook
ClassVIII Coding Teacher Handbook
TO CODING
GRADE VIII
Teacher Handbook
Version 1.0
INTRODUCTION
TO CODING
GRADE VIII
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 VIII teachers. This handbook uses block coding to explain advanced concepts
of coding using python in 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 application of coding in other subjects like mathematics.
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
CONDITIONALS IN DETAILS ............................................................................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? .......................................................2
1.4 Types of Control Structures ..................................................................3
1.5 Understanding IF-ELSE and ELSE-IF statements......................................3
1.6 Logical Operators ................................................................................4
1.7 Precedence of Logical Operators.............................................................6
1.8 Activity: Display if a number is odd or even..............................................7
1.9 Nested Conditional statement .............................................................. 12
1.10 Activity: The nested division problem ................................................. 13
1.11 Quiz time ...................................................................................... 14
1.12 What you have learned in this chapter ............................................... 16
GET CREATIVE WITH LOOPS......................................................................... 17
2.1 Lesson Structure .............................................................................. 17
2.2 Lesson Plan ..................................................................................... 17
2.2.1 Teacher’s Notes ........................................................................... 17
2.3 What will you learn in this chapter? ..................................................... 17
2.4 What are Loops? ............................................................................... 18
2.5 Exit Criteria ..................................................................................... 19
2.6 Activity: Cat Rain .............................................................................. 20
2.7 Activity: Create a staircase using for loop .............................................. 22
2.8 Activity: Create a staircase using while loop ........................................... 24
2.9 Activity: Raining pigs and pandas......................................................... 26
2.10 Quiz time ...................................................................................... 29
2.11 What have you learnt in this chapter? ................................................ 30
FUNCTIONS IN DEPTH ................................................................................. 31
I
3.1 Lesson Structure .............................................................................. 31
3.2 Lesson Plan ..................................................................................... 31
3.2.1 Teacher’s Notes ........................................................................... 31
3.3 What will you learn in this chapter? ..................................................... 31
3.4 Recap of functions............................................................................. 31
3.5 Function Parameters ......................................................................... 32
3.6 Activity: Calculating Volume of Cuboid.................................................. 33
3.7 Returning value from a function .......................................................... 37
3.8 Quiz time......................................................................................... 38
3.9 What have you learnt in this chapter?................................................... 39
PROGRAMMING WITH ARRAYS ...................................................................... 40
4.1 What will you learn in this chapter? ..................................................... 40
4.2 What are Arrays? .............................................................................. 40
4.3 Activity: Playing with colors................................................................. 40
4.4 Sorting an Array ............................................................................... 41
4.5 Searching in an Array ........................................................................ 41
4.6 Using Python to arrange an array in ascending order using bubble sort in
MakeCode................................................................................................ 42
4.7 Activity: Fun in Minecraft using arrays.................................................. 47
4.8 Activity: Building stairs ...................................................................... 49
4.9 Quiz time......................................................................................... 52
4.10 What have you learnt in this chapter? ................................................ 57
ADVANCED SEQUENCING ............................................................................ 58
5.1 What will you learn in this chapter? ..................................................... 58
5.2 What is a Sequence? .......................................................................... 58
5.3 Sequencing with Loops and Conditions ................................................. 59
5.4 Activity: Print number divisible by 3 from 1 to 100 .................................. 59
5.5 Quiz time......................................................................................... 62
5.6 What have you learnt in this chapter?................................................... 63
References .................................................................................................. 64
II
ETHICAL PRACTICES IN CODING
As you build capabilities around coding, you will be equipped to build software on your
own which will have an impact on society in general. So, it is very important to adhere
to ethical practices while building your own code. Below are some practices you must
remember as you keep learning to code.
You might be given access to confidential information like trade secrets, client data,
financial information etc. Ensure you do not disclose this information without proper
authorizations.
Page | 1
CONDITIONALS IN DETAILS
The teacher should introduce nested
1.1 Lesson Structure conditional statements with examples.
They should make sure that the children
1. IF-ELSE and ELSE-IF statement are not confused with these terms and
2. Logical Statements explain the pseudo code to the students
3. Practice Challenges
to improve their conceptual
4. Nested Conditional Statements understanding.
5. Quiz Time
Activity: Place students in groups of
three or four and guide them through
1.2 Lesson Plan
the exercises
For the exercise section, the teacher
Subtopics Number Method should make sure that the children are
of
comfortable with the Make Code platform
Periods
and they have it working on their
IF-ELSE and 3 Theory
ELSE-IF computers. The practice challenges can
statement be solved in several ways and do not
Logical Theory have a definite answer.
Statements
Assignment: Allow students to
Practice Practical
perform at least one practice exercise
Challenges
Nested Theory on their own
Conditional The teacher should encourage students
Statements to come up with unique solutions to the
Quiz Time 2 Practical
challenges in order to test their creativity
and understanding of the subject.
1.2.1 Teacher’s Notes 1.3 What will you learn in this
Discuss: What are logical statements
in real life?
chapter?
The teacher should introduce logical In this chapter you will understand
statements to the students by using real- conditionals in detail and how to use
life examples like the ones mentioned in conditionals in your code.
the curriculum. They can also ask the
students to come up with such examples
to encourage critical thinking.
Discuss: What are nested conditional
statements?
Page | 2
Here you will learn: Using this control structures,
programming has derived many types of
• Understanding IF ELSE and ELSE- control statements to suit different
IF statements needs. We will study them in upcoming
• Using logical operators topics.
• Using nested conditions
1.5 Understanding IF-ELSE and
ELSE-IF statements
Page | 3
assign a value to a variable. And “==” is
a relational(comparison) operator, i.e. it
is used to compare the value of two
variables.
ELSE-IF Statement
Page | 4
AND Operator Greater >= x >= y x is either
than or greater
The AND operator is used to see if two or equal to than or
more conditions are true. If all the equal to y
conditions are true, the AND operator Less <= x <= y x is either
returns TRUE. If any one of the than or less than
conditions fail, the AND operator returns equal to or equal to
FALSE. In python AND operator is y
Not != x! = y x not equal
denoted by and keyword. Some other
equal to to y
programming languages use “&&” as
AND operator.
Point to note over here is that “=” is an
assignment operator, i.e. it is used to
OR Operator assign a value to a variable. And “==” is
The OR operator is used to see if either a relational(comparison) operator, i.e. it
one of two or more conditions is TRUE. is used to compare the value of two
If any of the condition is true, the OR variables.
operator returns TRUE. If all the
conditions fail, the OR operator simply Activity: Can you create a triangle?
returns FALSE. In python syntax OR
operator is denoted by or keyword. Some Take this example of following figure of
other programming languages use “||” triangle with sides A, B and C. We know
as OR operator. the sum of two sides must be greater
than remaining side.
NOT Operator
We use the NOT operator to reverse or
negate a condition. If the condition is
true, NOT will return false and vice-
versa.
In python programming, not keyword is
used to denote not operator. Some other
programming languages use “!” as NOT
operator.
Relational operators Fig 1.2 Can you create a triangle.
Page | 5
say whether they can truly make a Now, if we want to solve the problem of
triangle. triangle in python coding, it becomes as
following.
Page | 6
1.8 Activity: Display if a number is odd or even
Let us now run through a practice exercise to understand logical operations. You should
try this exercise on the Minecraft Education Edition. You may set up the Minecraft
education edition from https://education.minecraft.net/get-started
Note: Minecraft is just one of the platforms for coding. You can use many similar
platforms available online to achieve similar results like – Scratch
(https://scratch.mit.edu/) and Code.org (https://code.org/)
At the end of this activity, you can expect following output on screen:
Page | 7
Page | 8
Page | 9
Page | 10
Now we will implement the example of odd-even to display some messages on the screen.
The program that you have written assigns 34 to a variable named as a. Then, in the
next lines of code, it checks whether variable a is now divisible by 2. If it is divisible, we
are displaying a message on the screen. At line 3, 5 and 6 the statement player.say is
used for displaying the message in the screen.
When you are done with typing the necessary lines of code, click on the green Start
button to execute the program. You will see the below result displaying number is even.
Page | 11
Activity 1.1
Create a program in Minecraft which
will check two numbers and display a
message saying if one is greater than
the other, or they are same.
if condition 1:
if condition 2:
statement 1
else
statement 2
elif condition 3:
if condition 4:
statement 3
else
statement 4
else:
statement 3
Page | 12
1.10 Activity: The nested division problem
We will now create the program to check if a number is divisible by 4 or 5 or both 4 and
5. To do that, open Minecraft Code Editor again. You can get the instructions from
previous sections for doing that.
Now that you have Minecraft Code Editor opened, type down the program as given below.
Make sure the indentations are correct.
After you are done with typing the code, click on the green Start button to execute the
program.
Result:
You will now see that message is displayed according to the logic we have written in our
program. It assigns 44 in a variable called number. Then it goes through our nested if-
elseif blocks to
Page | 13
display the result. If you have typed the lines of code properly, clicking on Start button
will display a message like below.
Now press C key to go back in the code editor. You can change the value of the variable
and run it again. By doing that, you can verify if the program is behaving as you have
expected.
Activity 1.2
Create another program which assigns total marks of a student to variable, and
display grade using the logic below.
• Total marks > 70, then grade A
• Total marks >49 and Total marks <=70, then grade B
• Total marks <= 49, then grade C
Page | 14
Question 2 Which of the following can create conditional statements?
Option 1 IF
Option 2 IF-ELSE
Option 3 Nested IF-ELSE
Option 4 All the above
Answer: Option 4
Standard Questions
Applied Project
Problem Statement: There are three children named Rohit, Priya and Pooja. Height of
Rohit, Priya and Pooja are 4.8 ft 5.2 ft and 5.1 ft respectively. Create a program in
Minecraft using block coding to find who is the tallest of three.
Sample solution:
Page | 15
1.12 What you have learned in this chapter
Page | 16
GET CREATIVE WITH LOOPS
The teacher should introduce loops to the The teacher should encourage students
students by using real-life examples. to come up with unique solutions to the
They can also ask the students to come challenges in order to test their creativity
up with such examples to encourage and understanding of the subject.
critical thinking.
2.3 What will you learn in this
• What are the different types of chapter?
loops?
• Definition of different types of Now that we already understand logical
loops operators in coding, let us dive deeper
• Break and Continue loops into the details of how to solve a coding
• Get introduced to pseudocode problem. By the end of this chapter, you
will learn:
Page | 17
2.4 What are Loops? Based on this we can write the below
pseudocode:
Everyday there are some tasks which
need to be done repeatedly.
Loops are programming elements which x=0
repeat a portion of the code for a set while x is not 10
number of times till the desired process x=x+1
is complete. Repetitive tasks are print(x)
common in programming and loops are
important to save time and minimize
errors.
The For Loop
For loop is needed for iterating over a
sequence.
For example – We need to calculate the
square of numbers present in a list.
Numbers= [1, 3, 5, 7, 13]
Loops make our code more manageable The pseudo code for this will look like
and organized. Let us now see what the
below:
different types of loops are:
1. While Loop
numbers = [1, 3, 5, 7, 13]
2. For Loop
sq = 0
3. Nested Loop
for x in numbers
The While Loop sq = x * x
print(sq)
The While loop can execute a set of
commands till the condition is true
While Loops are also called conditional
This is the result for the code
loops.
Once the condition is met then the loop
is finished
1
For example - Print from 1 to 10 9
25
Here, if we want to derive the loop from 49
this scenario, we have the following 169
conditions:
Condition: Write from 1 to 10
And the decision we are deriving is: The Nested Loop
Page | 18
nested loop. Consider the below specific task. It is a set of conditions that
program. must exist before you can declare a
program to be complete. Exit criteria is
numbers = [1, 2, 3] one of the most important components
alphabets = [a, b, c]
while defining a loop. As without an exit
for num in numbers
criterion, the program tends to enter in
for alphabet in alphabets
an infinite loop. These criteria differ from
print(alphabet)
program to program as per the
requirement.
We have used two loops here. The outer For example, while creating a loop to
loop, iterates over the numbers array print numbers from 1 to 1000, exit
and the inner loop iterates over the criteria is that loop should exit the block
alphabet array. So each of the alphabets of code when the 1000th number is
get printed 3 times.Finally, we have 9 printed, else the program will enter an
items that are printed. infinite loop.
a
b
c Activity 2.1
a Write a pseudocode to print prime
b
c numbers from 1 to 100
a
b
c
Page | 19
2.6 Activity: Cat Rain
You might have heard the phrase “raining cats and dogs”. In this exercise we will see
how you can rain cats from the sky. You should try this exercise on the Minecraft
education edition.
By now you should already have an idea of block coding. Below is how the exercise will
look when implemented with block coding with Minecraft
The final output of this exercise should look like as shown in the image below.
Page | 20
However, in this exercise, we will try to implement the same code using python.
Follow the below code block. We have used a for loop with range 100 – This means that
the loop will run 100 times.
Page | 21
So, the line mobs.spawn(CAT, pos(0, 10, 0)) will be executed 100 times.
After you click on play 100 cats will rain from the sky.
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
In this example we will create a block of stairs using tube coral black material where
the for loop will run 10 times so the height of the stairs will be 10 blocks and the width
will be three blocks.
Below is how the code will look when implemented with block code using Minecraft
education edition.
Page | 22
At the end of this exercise, the final output should look like shown in the below image.
Page | 23
So, we see how the same action is performed using a for loop. The detailed explanation
of the previous code is given below:
Step 1: Teleporting the builder to the specified position
Step 2: Creating a for loop which will run 10 times
Step 3: Inside the for loop we will move the builder forward by 2 steps
Step 4: Move the builder up by 1
Step 5: Finally the builder traces the path travelled and puts a block on the position
Step 6: Click on play. You will see a flight of stairs of height 10 and having width of 3
blocks.
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
In one of the previous activities we used for loop to create a staircase. Now let us create
a staircase with while loop.
If we implement this with block coding, below is how the code will look
Page | 24
At the end of this activity, the final output should look like shown in the image below.
Page | 25
Below are the detailed steps:
Step 7: Finally, the builder traces the path travelled and puts a block on the position
Step 8: Finally run the code by clicking on play then on the chat window type step 10
Results: You will see a stair of height 10 formed in your Minecraft world
We have already gone through an exercise to rain cats using for loop. We will now try to
take it further by raining Pigs and Pandas using while loop.
Below is how the code looks like when done using block code in Minecraft.
Page | 26
And when done with Python, the code will look like below.
Page | 27
At the end of this activity, the final output on screen should look like shown in the image
below.
Step 5: Lastly, update the value of variable “animals” to “animals = animals + 1”.
Step 6: Finally run the code by clicking on play then on the chat window type rain 100
Result: After you run the code you will see 100 pigs and 100 pandas dropping from the
sky in your Minecraft Environment
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
Page | 28
2.10 Quiz time
Option 1 Stop
Option 2 Break
Option 3 Exit
Answer: Option 2
Standard Questions
1. What are the different types of loops?
2. What is exit criteria?
3. What is exit criteria for While loop?
4. What is exit criteria for For loop?
5. What are nested loops?
1. Make 50 horses and 50 cats rain from the sky using for loop
2. Make stone stairs of height 15 blocks and width of 1 block using while loop
Page | 29
Applied Project
Problem Statement: Write an algorithm to find the HCF of two numbers using prime
factorization method.
Tip: Prime factorization method is used to find the prime factors of a composite number.
HCF is determined by multiplying the common factors of the two numbers.
Answer:
• By now you should have understanding about loops. Loops are used to repeat
a block of code
• Loops are also used to iterate through a sequence
• A loop within another loop is called nested loop
• Exit criteria is defined as condition which must be met before completing a
specific task.
• Break statement is used to exit from a loop
• Continue statement is used to skip some lines of code within a loop
Page | 30
FUNCTIONS IN DEPTH
The teacher should encourage students
3.1 Lesson Structure to come up with unique solutions to the
1. Function Parameters challenges in order to test their creativity
2. Return Values and understanding of the subject.
3. Quiz Time
Discuss: Function Return Types
Page | 31
simple name to a function, increases the
chances that the set of steps can easily
talked about and reused again and again
in the program.
V=L*B*H
VolumeOfCuboid (L, B, H)
{
return L * B * H
}
Page | 32
3.6 Activity: Calculating Volume of Cuboid
Let us now see how we can calculate the volume of a cube in Minecraft using the above
steps. You should try this exercise on Minecraft using the Make Code editor for
Minecraft which can be found here https://minecraft.makecode.com/
At the end of this exercise, the final output should look like shown in the screen below:
Let us now try to replicate this output on our screen by following the steps below:
Page | 33
Page | 34
Page | 35
Page | 36
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
We have already used functions that any value. When the program executes,
takes arguments as inputs and does the volume of cube gets calculated and
some operation with the arguments. assigned to the variable “volume”.
However, it becomes useless if the
However, a function can also give an
function doesn’t return the variable
output or return a value. That makes a “volume” to be used to assign the
function more useful.
calculated volume. It’s like in a
If we take the example of calculating the restaurant, the waiter takes the order,
volume of a cuboid that we were working goes into the kitchen and the food gets
on, the VolumeOfCuboid did not return cooked but he/she never comes back
Page | 37
with the food to the table. Returning a on the “Functions” button in the left
value is like the waiter coming back with panel and drag the “return” block to the
the cooked food to serve to the table. function VolumeOfCuboid as shown
below
Let us continue with the example we
have been working on in Minecraft. Click
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
Page | 38
Option1 True
Option2 False
Standard Questions
1. What are functions in programming?
2. What are the benefits of using functions?
3. Is it possible to return a value from function? If yes, how?
4. What are function parameters?
1. Define a function to calculate the cube of a number. The function should take a
number as argument and return the cube of that number.
2. Define a function to calculate volume of a sphere. The function should take radius
of the sphere as argument. Use the function for calculating cube of a number to
calculate the volume of the sphere. The function should return the calculated
volume. Call the function to get the volume of a sphere.
3. Define a function to calculate the simple interest of an amount. The function should
take the amount, the rate of interest and the time duration as arguments. The
function should return the calculated simple interest.
Applied Project
1. Problem Statement: A branch manager of a reputed bank wants you to develop a
software to calculate the simple interest. Create a program on Minecraft to calculate
the simple interest using functions.
Let the Principle amount = 100000
Time =2 years
Rate =5 %
Page | 39
PROGRAMMING WITH ARRAYS
4.1 What will you learn in this ▪ The variables in an Array are
chapter? always ordered sequentially with
index starting with 0
▪ You can only store variables with The above code snippet that we see is an
homogenous data types in an example of array.
Array
▪ Arrays are always static and Arrays are special type of variables
which can store a collection of values.
fixed in length and size
The values of an array can be accessed
by referring to an index number.
Page | 40
For example, to get the first item in an As you can see the items are not
array you will write your code like below arranged in any order. Sorting is the
process of ordering items in a collection.
Above array when sorted in ascending
order will look like below.
To modify the value of the first item in
the array you will write:
Python has inbuilt sort function to order
an array. The sort() method sorts the list
ascending by default.
Question: How to create an array of a
sequence of integers between 0 and 11. Example:
Result:
Page | 41
4.6 Using Python to arrange an array in ascending order using
bubble sort in MakeCode
Before we start this activity let us first understand what bubble sort is:
Bubble sort is a method of sorting that works by repeatedly swapping adjacent elements
if they are in incorrect order. In this problem, you need to sort a given set of numbers
in ascending order using bubble sort.
Let us consider a set of numbers 1, 5, 4, 3, 2; that needs to be sorted in ascending order.
If the number on the left is greater than the number on the right, it swaps the two
numbers. This is done until the numbers are sorted in ascending order.
1 5 4 3 2
• Then we compare the numbers 5 and 4
• Since 5 is greater than 4, we will swap these two numbers.
1 5 4 3 2
• Next, we compare 5 and 3
• Since 5 is greater than 3, we will swap the two numbers.
1 4 5 3 2
• Lastly, we compare 5 and 2
• Since 5 is greater than 2, we will swap these two numbers
Page | 42
1 4 3 5 2
• The list of the numbers is rearranged as follows:
• Notice 5 is the largest number in this list and arranged at the last position.
1 4 3 2 5
• We again start from the beginning and compare 1 with 4. Since 4 is greater
than 1, no change is made.
1 4 3 2 5
1 4 3 2 5
Page | 43
1 3 4 2 5
• Lastly, we compare 4 and 5. Since, 5 is greater than 4, no change is made.
1 3 2 4 5
• We again start from the beginning and compare 1 with 3. Since 3 is greater
than 1, no change is made.
1 3 2 4 5
1 3 2 4 5
• Next, we compare the numbers 3 and 4. Since 4 is greater than 3, no change is
made.
Page | 44
1 2 3 4 5
• We again start from the beginning and compare 1 with 2. Since 2 is greater
than 1, no change is made.
1 2 3 4 5
1 2 3 4 5
• If we have 5 numbers, then the maximum time taken to sort the list will be 25
iterations.
Page | 45
Output for the code:
When you click on play the array will be sorted in ascending order.
Page | 46
4.7 Activity: Fun in Minecraft using arrays
Page | 47
In this activity we will create an array of flowers and calculate the length of the array to
create a flight of stairs.
Step 3: Create a variable called length which is the length of the array flower
Step 4: Start a for loop which will run as many times as the length of the array
Step 6: Finally, the builder traces the path travelled and puts a block on the position
Step 7: When you hit play you will that there is a golden stair created.
Page | 48
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
Now we are going to build a flight of stairs using the material present in the 1 st position
of the array.
At the end of this activity, the final output should look like shown in the image below:
Page | 49
Using Python:
Page | 50
Here are the detailed steps:
Step 1: Teleporting the builder to the entered position
Step 2: Make an array named material
Page | 51
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
Standard Questions
1. What are arrays in programming?
2. Explain how arrays are indexed in programming.
3. Explain how you can sort an array {67, 23, 98, 19} using Python?
4. How do you search a particular value from an array in Python?
1. Make an array of animals (10 animals in the array) and use for loop which runs
as many times as the length of the array to drop horses from the sky.
2. Make an array of animals (10 animals in the array) and use for loop which runs
as many times as the length of the array to drop animal present on the 4 th
position (Tip: The 4 th position will be indexed as 3) from the sky
Page | 52
Applied Project
Problem Statement: There is a robot which can read the numbers written on the
cards only when kept close to its eyes. It can pick only one card containing numbers
in its left hand and another in its right hand. Can you help it to arrange the cards in
ascending order using bubble sort? Let’s try it on the numbers 1, 5, 4, 3, 2.
Explanation:
In the first move, the first two numbers 1 and 5 are compared. Since 1 < 5 therefore the
numbers are not swapped.
In the second move, the second and third numbers 5 and 4 are compared. Since 5 > 4
therefore the numbers are swapped.
Page | 53
In the third move, the third and fourth numbers 5 and 3 are compared. Since 5 > 3
therefore the numbers are swapped.
In the fourth move, the fourth and fifth numbers 5 and 2 are compared. Since 5 > 2
therefore the numbers are swapped.
Page | 54
In the fifth move, the first and second numbers 1 and 4 are compared. Since 1 < 4
therefore the numbers are not swapped.
Note that the number 5 is sorted. Let us repeat the same steps for numbers 1 ,4,3 and
2.
In the sixth move, the second and third numbers 4 and 3 are compared. Since 4 > 3
therefore the numbers are swapped.
In the seventh move, the third and fourth numbers 4 and 2 are compared. Since 4 > 2
therefore the numbers are swapped.
Note: The number 4 is sorted. Let us repeat the same steps for numbers 1 3 and 2.
In the eighth move, the first and second numbers 1 and 3 are compared. Since 1 < 3
therefore the numbers are not swapped.
Page | 55
In the ninth move, the second and third numbers 3 and 3 are compared. Since 3 > 2
therefore the numbers are swapped.
Page | 56
After tenth moves we can sort the numbers in ascending order. This process of arranging
numbers is called bubble sort.
Page | 57
ADVANCED SEQUENCING
Page | 58
5.3 Sequencing with Loops and
Conditions
Page | 59
Let us start to replicate this activity to Iterate a loop from 0 to 100 as shown below
Page | 60
Page | 61
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org
Standard Questions
1. Explain what is a sequence in programming?
2. Draw a flowchart to demonstrate sequence of activities that you do while getting
ready for school.
3. Write a pseudocode to explain sequence of activities that you perform while giving
an exam.
Applied Project
1. Problem Statement: Write a flow chart for the algorithm to determine if a number
is perfect square.
Tip: A perfect square is a number which can be expressed as the square of a given
number. 25 is a perfect square as 25 can be expressed as 5*5 or 5 2 .
Answer:
Page | 62
5.6 What have you learnt in this chapter?
Page | 63
REFERENCES
Microsoft. 2021. Minecraft MakeCode | Rain cats and dogs. [Online]. [25 February
2021]. Available from: https://minecraft.makecode.com/examples/cats-vs-dogs
Code of Ethics. 2021. Code of Ethics. [ONLINE] Available at:
https://www.acm.org/code-of-ethics
Page | 64