ClassVII Coding Teacher Handbook
ClassVII Coding Teacher Handbook
INTRODUCTION
TO
TO CODING
CODING
GRADE VII
GRADE VII
Teacher Handbook
Teacher Handbook
Version 1.0
INTRODUCTION
TO CODING
GRADE VII
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 VII teachers. This handbook uses block coding to explain concepts of coding
and introduces 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
I
2.16 What have you learnt in this chapter? ................................................ 40
Fun with Functions ...................................................................................... 41
3.1 Lesson Structure .............................................................................. 41
3.2 Lesson Plan ..................................................................................... 41
3.3 Teacher’s Notes................................................................................. 41
3.4 What will you learn in this chapter? ..................................................... 42
3.5 What exactly are Functions? ............................................................... 42
3.6 Examples of simple functions in Arcade ................................................ 43
3.7 Activity: Adding two integers ............................................................... 46
3.8 How to reduce redundancy using Functions? ......................................... 48
3.9 Advantages of using Functions ............................................................ 49
3.10 What are different Function Parameters? ............................................ 49
3.11 Activity – Finding the square of a number ........................................... 49
3.12 Activity – Arranging the Books .......................................................... 51
3.13 Activity: Calculating area of a circle ................................................... 53
3.14 Can Function return a value? ........................................................... 61
3.15 What is an event? ........................................................................... 69
3.16 What is an event handler? ............................................................... 69
3.17 Quiz Time ..................................................................................... 70
3.18 What have you learnt in this chapter? ................................................ 74
Understanding Arrays & Collections ................................................................ 75
4.1 Lesson Structure .............................................................................. 75
4.2 Lesson Plan ..................................................................................... 75
4.3 Teacher’s Notes................................................................................. 75
4.4 What will you learn in this chapter? ..................................................... 75
4.5 What are Collections? ........................................................................ 76
4.6 Activity – Algorithm for a perfect square ................................................ 76
4.7 Activity Building a Zoo ....................................................................... 77
4.8 What are Arrays? .............................................................................. 84
4.9 Examples of arrays using Arcade ......................................................... 90
4.10 How can we iterate over collections? .................................................. 91
4.11 Modifying Collections ...................................................................... 91
4.12 Quiz Time ..................................................................................... 93
II
4.13 What have you learnt in this chapter? ................................................ 95
Hello World with Code................................................................................... 96
5.1 Lesson Structure .............................................................................. 96
5.2 Lesson Plan ..................................................................................... 96
5.3 Teacher’s Notes................................................................................. 96
5.4 What will you learn this chapter? ......................................................... 96
5.5 What is a Programming Language?....................................................... 96
5.6 Activity – Sorting the list..................................................................... 97
5.7 Getting used to syntax ..................................................................... 100
5.8 What are Variables and Data types in programming? ............................. 101
5.9 Activity: Building a Calculator ........................................................... 102
5.10 Quiz Time ................................................................................... 108
5.11 What have you learnt in this Chapter? ............................................. 111
References ................................................................................................ 112
III
ETHICAL PRACTICES IN CODING
Let us start this course by getting familiar with some fundamental principles of ethical
coding.
6. As you grow as a software developer, you will be utilizing code developed by other
persons as well. It is essential to provide disclosure to all such work. Never take credit
for another person’s work
7. Do not claim ownership of work that others have shared as public resources
With these principles in mind let us get started with this book.
1|Page
VARIABLES IN REAL LIFE
The teacher should explain all the Math
1.1 Lesson Structure Operations in Programming to the
students. They should ensure that the
1. What is Variable Initialization? children are not confused with these
2. How do we validate user input in terms and explain the pseudo code to the
programming? students to improve their conceptual
3. Performing Math Operations in understanding.
Programming
4. Quiz Time Activity: Place students in groups of
three or four and guide them through
the exercises
1.2 Lesson Plan
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
What is Variable 2 Theory computers. The practice challenges can
Initialization? be solved in several ways and do not
How do we Theory have a definite answer.
validate user
input in Assignment: Allow students to
programming? perform at least one practice exercise
Performing Math Practical on their own
Operations in
Programming The teacher should encourage students
Quiz Time 2 Practical to come up with unique solutions to the
challenges to test their creativity and
understanding of the subject.
2|Page
1.5 What is Variable
Initialization? Let us now do a practice exercise in
To use variables in programming, we Minecraft: Education Edition to
need to create the variables and assign understand how variable initialization
them a reference in computer memory. works in programming. You setup
Once we create a variable, we also need Minecraft education edition from
to assign it a value before it is used at https://education.minecraft.net/get-
all. This process of assigning a value to started.
variable is called Initialization.
A variable that is not initialized ever has
an undefined value. Such a variable
cannot be used until it is assigned with
a certain value. In a case where a
variable is declared (read – created) but
it is not initialized, we can assign it a
value in later steps using assignment
operators.
b = “Hello”
3|Page
4|Page
5|Page
We have now completed this exercise and learnt how can create and initialize variables
in programming.
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
6|Page
Boolean data in Python is used to define
Boolean variables. Boolean variables
1.6 Data Types in
can hold only two values in it, either
programming “true” or “false”.
Depending on the requirement,
programming languages offer wide
variety of data types to suit the 1.7 How do we validate user
programmers’ needs. input in programming?
Below are some basic data types
available in Python:
An important part of making sure that
1. Integer your program works fine is to validate
2. Floating-Point Number that the user enters valid values in the
3. String places where you are expecting an input
4. Boolean from the user. For example, consider
someone asking you a question, “What
did you have for lunch today?”. To
Integer answer this question, you should
answer the person what food item you
Integer is a data type used to define had for lunch. Imagine you answering
integer variables. Integers can be of any back “I have pink box in my hand”. This
length. They can be any positive or is obviously, not an acceptable answer to
negative whole number. the question that was asked and may
confuse the person who asked the
question.
Floating-Point Number
Similarly, in programming, whenever
A floating-point number in Python is you create a variable with a specific data
used to define decimal numbers and is type, and you are expecting a user to
accurate up to 15 decimals places. enter a certain value in that data type,
you should make sure that the user
enters the right type of value, which
String won’t cause any error during program
execution. This validation of Input plays
A string in Python is a sequence of a vital role while writing a program.
Unicode characters. It is used to define
any form of strings ex. Text, A computer program behaves exactly the
Alphanumeric etc. In Python, we can use way how a flowchart flow. Any deviation
single quotes, double quotes or triple of data type in the user's input will result
quotes to define strings. Multi-line in an error by program.
strings in Python can be represented
A very common way of validating user
using triple quotes. input in flagging out the wrong input. To
do this, common practice is to set a flag
in program which has a default value
Boolean
7|Page
“false”. If the user input matches the note that subtraction can only be
expected input, you will reset the flag to carried out on Integer, Float, Double
true and execute. If the user value is set datatypes only.
to false, you will abort the execution by
For example, if there are two integer
throwing an error message. variables “a” and “b” declared in your
program. Where a = 3, and b = 2. If we
perform the subtraction operation of
1.8 Math Operations in
these variables in programming, the
Programming result is going to be 1.
Multiplication
Now that we have understood how to
declare and initiate a variable and how Multiplication operation is used to
to validate the user input let us now perform the mathematical multiplication
understand how we can perform of two variables. In programming, we
mathematical operations of these refer to “*” as a symbol of multiplication.
variables. Please note that multiplication can only
be carried out on Integer, Float and
In programming, there are following
Double datatypes.
operations that you can perform on
variables. Division
Addition Division operation is used to perform
the mathematical division of two
Addition operation is used to perform
variables. In programming, we refer to
mathematical addition of two variables.
“/” as a symbol of division. Please note
In programming, we refer to “+” as a
that Division can only be carried out on
symbol of addition. Please note that
Integer, Float and Double datatypes.
Addition can only be carried out on
Integer, Float, Double and String Modulus
datatypes only. You can use this
operator to concatenate two strings on Modulus operation is used to perform
the mathematical remainder of two
either side of the operator.
variables. In programming, we refer to
“%” as a symbol of modulus. Modulus
For example, if there are two float
variables, “x” and “y” declared in your operator divides variable on the left to
the variable on right and returns the
program. Where x = 1.1, and y = 2.2. If
remainder. Please note that modulus
we perform addition operation these
can only be carried out on integer and
variables in programming, the result is
going to be 3.3 float datatypes in Python. For example,
if there are two integer variables “x” and
Subtraction “y” declared in your program. Where x =
10, and y = 3. If we perform modulus
Subtraction operation is used to
operation on these variables in
perform mathematical subtraction of
programming, the result is going to be
two variables. In programming, we refer
1.
to “-” as a symbol of subtraction. Please
8|Page
1.9 Quiz Time
9|Page
Question 5 Which of the following shows the syntax of an assignment statement?
Option 1 VariableName = expression;
Option 2 Expression = expression;
Option 3 Expression = VariableName;
Option 4 datatype = VariableName;
Answer: Option 1
Standard Questions
Teacher’s Note: The teacher should explain to the students the logic to figure out if
the string is palindrome or not. This will help the students to understand how to
10 | P a g e
apply this logic in a program. The teacher should encourage the students to do the
problem on their own.
2. Write a program to count the occurrence of the letter “a” in string “We are a
family”.
Teacher’s Note: The teacher should explain to the students the logic to count the
number of occurrences of letter “a” in the given string. This will help the students to
understand how to apply this logic in a program. The teacher should encourage the
students to do the problem on their own.
Applied Project
Teacher’s Note: The teacher should explain the students the project so that they can
understand it and create the corresponding program in Arcade. The teacher should
encourage the students to do the problem by their own. The block code will be
different for all the students.
By now you:
• Should have an understanding about variables
• Should have an understanding about initialization of variables.
• Should know how to apply different mathematical operations on different
data types.
11 | P a g e
SEQUENCING WITH BLOCK CODING
2.1 Lesson Structure
1. What is Sequencing?
2. What is a bug? 2.3 Teacher’s Note
3. Activity: Drawing a Rectangle in
Minecraft
Discuss: What is Sequencing in real
4. How to apply the concept of
life?
Sequencing in Loops and
Conditionals? The teacher should introduce sequencing
5. Activity: Making a Square in to the students by using real-life
Minecraft using Loops examples. They can also ask the
6. Practice Assignment students to come up with such examples
to encourage critical thinking.
12 | P a g e
The teacher should encourage students 2.6 What is Sequencing?
to come up with unique solutions to the
An algorithm is a detailed step-by-step
challenges to test their creativity and
process that needs to be followed in
understanding of the subject.
order to complete a task or to solve a
problem. There are three basic building
2.4 What will you learn in this blocks that can be used when designing
algorithms:
Chapter?
• Sequencing
1. What is sequencing?
• Selection
2. Why is it important to follow a
• Iteration
sequence in programming?
3. How to reduce steps in a These building blocks help us to convert
sequence with loops and any complex problem into a well-defined
conditional operators? solution that can be understood and
implemented by others using
programming. For example, how would
you design an algorithm for your
2.5 Recap of Loops
morning routine?
1. In programming, repetition of a line
or a block of code is also known as • Wake up
iteration. • Brush your teeth
2. A loop is an algorithm which • Take a bath
executes a block of code multiple • Have breakfast
times till the time a specified • Go to school
condition is met.
3. The break statement modifies the In this chapter, we will learn about the
normal flow of execution while it first building block of algorithms –
terminates the existing loop and sequencing.
continues execution of the
A sequence is a list of activities that are
statement following that loop.
done one after another. Sequencing
4. Whenever a program encounters a
refers to the specific order in which we
continue statement, the control
need to perform the activities in order to
skips the execution of remaining
get the desired output.
statements inside the loop for the
current iteration and jumps to the Designing an algorithm for How to Make
beginning of the loop for the next a Sandwich
iteration.
5. When there is a loop inside another
loop, it is called a nested loop.
13 | P a g e
Every day, we do many activities in a 2.7 Examples of Sequence,
sequence. For example, think of how you Selection and Iteration
would make a sandwich. If you had to
write down the steps for making a To understand concept of sequencing in
sandwich, would it be like the steps programming, take a look at below
given below? algorithm to swap two numbers:
Step 1: Start
Step 2: READ num1, num2
14 | P a g e
person is named as a senior citizen if his follow the flow as shown in the Fig 2.1
age is above 60 years old. flowchart.
print(“Person is a senior
citizen”);
else
print(“Person is not a senior
citizen”);
15 | P a g e
2.8 What is a Bug? For example, suppose you create a boat
which is expected to sail in ocean. Now
A bug is a terminology
when the boat is ready and you try to
used to describe any
sail it in the water, you realize that there
unexpected problem in
is a small hole in the bottom on the boat
your program. Just like from where water is seeping in. This
we learnt in the past water seeping in the boat at a slow speed
topics, we follow a sequence of activities
may create a problem for the boat in the
to complete a program. This program is
long run. Thus, this hole in the bottom
expected to return a specific output. Any of the boat can be termed as a “bug” in
deviation in the expected and actual
programming.
output of the program is known as a
bug.
Let us now see how we can make a rectangle in Minecraft using the above steps. You
should try this exercise on Minecraft using the MakeCode editor for Minecraft, which
can be found here https://minecraft.makecode.com/
16 | P a g e
Once you complete this exercise, the final output should look like as shown in the
screenshot below:
Let us now follow below steps to get this output on our screen:
17 | P a g e
Now follow the following steps
18 | P a g e
19 | P a g e
20 | P a g e
21 | P a g e
If you complete the steps above, you should be able to create a rectangle.
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 (https://code.org/).
In this activity, we will create a game with 2 sprites, a Player sprite and an Apple sprite.
The objective of this game is to chase and catch the wandering apple and collect as
many points as possible before the time runs out. Every time the apple is caught, points
are added, and the timer is restored.
You should try creating this game on Arcade using the MakeCode editor which can be
found here https://arcade.makecode.com
22 | P a g e
Now follow the steps mentioned below to create the game.
23 | P a g e
24 | P a g e
25 | P a g e
26 | P a g e
27 | P a g e
28 | P a g e
29 | P a g e
30 | P a g e
Note: Arcade 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
31 | P a g e
nested loop. How it works is that first
success condition of outer loop triggers
the inner loop which runs and reaches
Activity completion. This combination of loops
• Create a square of size 10 and inside loop is helpful while working with
spawn 2 sheep in it. requirements where user wants to work
• Create two squares such that they of multiple conditions simultaneously.
There is no restriction on how many
have a common side. Spawn 2
loops can be nested inside a loop.
chickens in one square and 2 cows
in the other.
2.12 Apply Loops and
2.11 Types of Loops Conditionals with
sequencing
As we have studied, use of loops make
our code manageable and organized.
Now, let us discuss the other two
Mainly, there are three different types of
important aspects of an algorithm –
loops:
selection and iteration.
1. While Loop
Selection refers to the situation in which
2. For Loop the algorithm needs to make a choice
3. Nested Loop
between two or more alternatives. It is
like asking questions like “Is it raining?”.
If the answer to the question is true, the
While Loop algorithm follows one path. If the answer
The While Loop can execute a set of is false, the algorithm follows a different
commands till the condition is true. path.
While Loops are also called conditional Iteration refers to the process of doing
loops. the same task over and repeatedly, until
Once the condition is met then the loop a certain task is complete, or a certain
is finished. condition is met. The iteration can also
be set to run for a specific number of
times. For example, think of a race in
which a car must go around a track five
For Loop
times. The car will keep going around
For Loop is needed for iterating over a the track repeatedly until it completes
sequence. A for loop executes for a five laps. Once that is done, it will exit
specific number of times. the track.
32 | P a g e
working on a sequence, you will notice For example, in the last exercise, while
that certain activities in the sequence creating a rectangle, we had to turn right
are repeated. We can reduce the number after drawing a line and we had to do so
of steps of the sequence by using a loop three times.
along with certain conditions to check
when the loop should stop. Can we use a loop to reduce the number
of steps?
With an example, let us now understand sequencing with loops and conditionals. What
would be the steps to draw a square of side 5 cm on your screen?
Do you notice a pattern getting repeated in the steps? Let us see how we can use a loop
to reduce the steps by using the Minecraft platform.
First, create a new project called “Make Square”. Once you create your project, you
should see the editor below
At the end of this exercise, the final output should look like the one shown in the image
below:
33 | P a g e
34 | P a g e
35 | P a g e
36 | P a g e
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 (https://code.org/).
37 | P a g e
If you notice, there is a pattern which Arun follows while distributing sweets. He takes
the chocolates out from his bag, gives one chocolate to a student, moves to the next
student and repeats the same steps again till the sweets are distributed within all the
students.
This is an example of an iterative process. Repetition of a set of steps with a defined end
– in this case the repetition ended when all the students in the class were given
chocolates.
38 | P a g e
Question 4 What is selection in programming?
Standard Questions
Teacher’s Note: The teacher should explain to the students the logic used to find the
cube of a number. The teacher should encourage the students to think how this logic
can be written in the algorithm using the concept of iteration that we learnt in this
chapter.
39 | P a g e
2. Draw a flowchart to explain the iterative process that Arun followed while
distributing birthday sweets.
Teacher’s Note: The teacher should explain the students the Arun’s example so that
they can understand it and draw a flowchart for sequence of activities. The teacher
should encourage the students to do the problem by their own.
Applied Project
Create a rectangle of length 5 and height 3 using a loop (repeat block) in Minecraft.
Teacher’s Note: The teacher should explain to the students the project to understand it
and draw the rectangle in Minecraft. The teacher should encourage the students to do
the problem on their own. The steps and logic will be different for all the students.
By now you:
• Should have an understanding about the basics of algorithms.
• Should have an understanding about sequencing and its importance.
• Should know how to apply loops and conditions to simplify sequencing.
40 | P a g e
FUN WITH FUNCTIONS
What is an Practical
event?
3.1 Lesson Structure
Practice 1 Practical
1. What exactly are functions? Assignment
2. Activity: Adding two integers
3. How to reduce redundancy using
functions? 3.3 Teacher’s Notes
4. Advantages of using functions Discuss: What are functions?
5. What are different function
parameters? The teacher should introduce functions to
6. Activity – Finding the square of a the students by using real-life examples.
number They can also ask the students to come
7. Activity – Arranging the books up with such examples to encourage
8. Activity – Calculating area of a critical thinking.
circle Discuss: How can functions help in
9. Can function return a value?
reducing redundancy in a program?
10. What is an event?
11. What are event handlers? The teacher should give examples of
12. Practice Assignment repeated blocks of code and relate how
using functions in this place can help in
reducing the redundancy of the code.
3.2 Lesson Plan They should ensure that the children are
not confused with these terms and
Subtopics Number Method
of explain the pseudo code to the students
Periods to improve their conceptual
What exactly are 4 Theory understanding.
functions?
Activity: Place students in groups of
How to reduce Theory
three or four and guide them through
redundancy
the exercises
using functions?
What are Theory For the exercise section, the teacher
different should make sure that the children are
function comfortable with the Make Code platform
parameters?
and have it working on their computers.
Activity – Practical
The practice challenges can be solved in
Calculating area
of a circle several ways and do not have a definite
answer.
41 | P a g e
Assignment: Allow students to A function is a block of code made up of
perform at least one practice exercise a set of steps that results in a single
on their own specific action. The programmer will give
this action a simple name. Giving a
The teacher should encourage students
simple name to a function, increases the
to come up with unique solutions to the chances that the set of steps can easily
challenges to test their creativity and
talked about and reused again and again
understanding of the subject.
in the program.
42 | P a g e
3.6 Examples of simple functions in Arcade
Example 1: Calling a function which has no parameters.
43 | P a g e
Example 2: Calling a function with a single parameter
44 | P a g e
Example 3: Calling a function to print statements.
45 | P a g e
3.7 Activity: Adding two integers
In Minecraft Editor, click on “Make a Function” button from “Functions” link in toolbox.
46 | P a g e
47 | P a g e
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
48 | P a g e
out repeated commands helps to
minimize errors, keeps code short, and
saves programming time.
49 | P a g e
50 | P a g e
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 activity, you will learn about the concept of “Sorting” in programming.
Suppose you have a lot of books with you. However, all these books are mixed up. Now,
if you want to arrange these books, you can do it in many ways.
In Sorting, we take a jumbled set of objects and arrange them in some kind of order.
For Sorting, we need to know how to compare two items. So, we will ask questions like:
Which book is taller/shorter?
51 | P a g e
Let us understand sorting of books from shortest to tallest with help of flowchart in Fig
2.0.
There are many clever sorting algorithms that computers use. They help you sort
different kinds of items very quickly.
Sorting is helpful because:
52 | P a g e
3.13 Activity: Calculating area of a circle
Let us now see how we can calculate the area of a circle in Minecraft using the above
steps. You should try this exercise on Minecraft using the MakeCode editor for
Minecraft, which can be found here https://minecraft.makecode.com/
53 | P a g e
54 | P a g e
55 | P a g e
56 | P a g e
57 | P a g e
58 | P a g e
59 | P a g e
60 | P a g e
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
Till now we have only used functions in a way wherein once a function is called,
execution of all the logic and display of the output was done inside the function.
However, as discussed before, the main purpose behind using functions is to get rid of
repetitive chunks of code. Thus, the usefulness of using a function in a prog ram comes
to the forefront, when an operation performed inside a function gives back a value,
which can be used later in the program to generate meaningful results.
61 | P a g e
As an example, consider a scenario where in we calculate the square of a number using
a function, calculate the cube of another number using another function and then add
the results generated from these two functions and print them.
Let us see how we can implement the above example via Minecraft
62 | P a g e
63 | P a g e
64 | P a g e
65 | P a g e
66 | P a g e
67 | P a g e
68 | P a g e
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
69 | P a g e
This “on player walk” block is an event
handler. Agent mode forward is the
action that occurs with this event.
70 | P a g e
Question 4 A function can return a value
Option 1 True
Option 2 False
Answer: Option 1
Standard Questions
71 | P a g e
def test(x, y):
if x > y:
return y
print(test1(2, 7, -1))
Answer: -1
def sum(numbers):
total = 0
for x in number:
total += x
return total
print ( sum ( ( 1 , 2 , 3 , 4 , 5 ) ) )
Teacher’s Note: The teacher should explain to the students the logic used to print
even numbers of screen. The teacher should encourage the students to think how
this logic can be written in the algorithm using the concept of functions that we
learnt in this chapter.
72 | P a g e
2. Write a function to do sort the elements [34,12,89,56,98,101] from biggest to
smallest.
Teacher’s Note: The teacher should explain to the students the sorting algorithm that
we learnt in the chapter. The teacher should encourage the students to think how
this logic can be written in the algorithm using the concept of sorting that we learnt
in this chapter.
3. Write a function to find the highest number in the array of [1, 87, 09, 18, 11]
Teacher’s Note: The teacher should explain to the students the logic used to find
highest number in an array. The teacher should encourage the students to think
how this logic can be written in the algorithm using the concept of functions that we
learnt in this chapter.
4. Write a function to find the modulus of 3 and 6.
Teacher’s Note: The teacher should explain to the students the logic used to find
modulus of two variables. The teacher should encourage the students to think how
this logic can be written in the algorithm using the concept of functions that we
learnt in this chapter.
Applied Project
Teacher’s Note: The teacher should explain to the students the project to understand
it and calculate the volume of cylinder in Minecraft. The teacher should encourage
the students to do the problem on their own. The steps and logic will be different for
all the students.
2. Create a block code which computes product of (sum of two random numbers)
with the (difference of two random numbers) using functions.
Teacher’s Note: The teacher should explain to the students the project to understand
it and calculate product of two random number in Minecraft. The teacher should
encourage the students to do the problem on their own. The steps and logic will be
different for all the students.
73 | P a g e
3.18 What have you learnt in this chapter?
By now you:
• Should have an understanding about the usefulness of using functions in
code.
• Should know how to define ,call a function and pass parameters in a
function.
• Should know how different types of value are returned by a function.
74 | P a g e
UNDERSTANDING ARRAYS & COLLECTIONS
4.3 Teacher’s Notes This chapter will teach you how we can
Discuss: What are Collections? work with large set of data in
programming. What are Arrays and its
The teacher should introduce the concept practical implementation in computers.
of Collections to the students by using This chapter will also give you an
real-life examples like those mentioned in overview of collections. We will work on
the curriculum. They can also ask the some fun exercises to get better
students to come up with such examples understanding of these concepts
to encourage critical thinking.
75 | P a g e
4.5 What are Collections? • How quickly can you determine
whether a number is a perfect
square?
A collection is nothing but a container • And, if a number is a perfect
that groups multiple items into a single square, how can you find out its
object. Collections are used to store square root?
data. We can also retrieve and • Can you write the steps for
manipulate data that is stored in the finding the same for any given
Collections. large number?
• Let us try with a few examples
and identify the repeatable steps
In real world, you can consider a in the process.
collection of cards, a telephone directory
or a mailbox to be an example of
Collections. Example 1: Is 36 a perfect square?
Advantages of using Collection We can use the below algorithm to solve
this problem:
In the below algorithm, “n” is the input
• Collections allow programmers to number (36 in this case)
group multiple items into a
common set Output is true if the number is a perfect
• Grouping of items makes it easier
to identify and perform different begin
operations on them like retrieving
and modifying data for num :=1, num <= n, increase num
• It increases the performance of by 1:
the program if n is divisible by num, and n / num
• It increases productivity and = num, then
reduces operational time.
return true
76 | P a g e
1. Say number is n
2. Start a loop from 1 to n/2
3. During iteration, for every integer
‘i’, calculate x = i*i
4. Now with this ‘x’ there are 3
possibilities:
a. If x==n then n is a perfect As you must have noticed, the number
of times we multiply, and compare is
square, return true.
b. If x > n then x has crossed reduced significantly in the above
algorithm. This is how we can use
the n, is not perfect square.
optimized algorithm to find the square of
Return false
c. If above step a or b are not numbers.
true, then continue.
You can store animals in an array and spawn them wherever you like. We’ll use this
capability to build a fenced-in animal pen and create an instant zoo anytime we want.
When this project starts up, it will create an array and fill it with animals of your choice.
Step 1: Create a new MakeCode project called “Zoo”.
Step 2: In “Loops”, there is an “on start” that will run its commands once, as soon as
the project starts up. Drag that block into the coding Workspace.
Step 4: From “Variables”, drag “set” into the “On start” block.
77 | P a g e
Step 5: Using the drop-down menu in “set”, select the animalarray variable.
Step 6: Click on the Advanced tab in the Toolbox to display the “Arrays” Toolbox drawer.
Step 8: Click the Plus (+) sign on “create array with” to add 7 more slots in your array.
The total length of your array should be 8.
Step 9: From “MOBS”, drag an Animal block into the first slot of “create array with”.
78 | P a g e
Step 11: Create a zoo with 8 different types of animals. Be aware that certain animals
will eat other animals! For example, ocelots and chickens don’t get along very well.
Think about what kind of zoo you want, and plan accordingly.
Step 12: Using the drop-down menus in the “animal” blocks, select different types of
animals in your array.
79 | P a g e
Step 13: Now that you have your animalarray set up, let’s work on creating a fenced-
in enclosure for your zoo. You will use the “BUILDER” blocks for this. The Builder is
like an invisible cursor in the game that can place blocks along a path very quickly.
You will direct the Builder to go to a point in the southeast corner, and create a mark,
which is an invisible point of reference. Then you will give it a series of commands to
make it trace out a square. Finally, the builder can place fences along this path.
Step 14: From “PLAYER”, drag an “on chat command” block to the Workspace.
Step 15: Rename the command “pen”.
Step 16: Click on the Advanced tab in the Toolbox to display the “BUILDER” Toolbox
drawer.
Step 17: From “BUILDER”, drag “builder teleport to” into “on chat command "pen"”
Step 18: Recall that Minecraft coordinates are always specified in X, Y, Z coordinates
where X is west to east and Z is north to south. We want the Builder to start in the
northeast corner of the pen in relation to the player, so go ahead and change the
coordinates to specify a location 5 blocks east and 5 blocks north of your position.
Step 19: In “builder teleport to”, change the position values to (~5, ~0, ~-5).
80 | P a g e
Step 20: Let’s make sure the Builder is facing the right way so that it draws the pen
around you. After the builder is facing the correct direction, you can then have it place
a starting mark.
Step 21: From “BUILDER”, drag “builder face” out and under “builder teleport to”. The
default ‘face West’ is fine.
Step 22: Next, from “BUILDER”, grab a “builder place mark” to put after the “builder
face”.
Step 23: From “LOOPS”, drag a “repeat” loop and place it after “builder place mark”. A
square has four sides so repeating four times is great.
Step 24: From “BUILDER”, drag a “builder move” into the “repeat” loop.
Step 25: Type 10 into “builder move” to make the sides of your pen 10 blocks.
Step 26: From “BUILDER”, drag “builder turn” after the “builder move” block.
Step 27: From “BUILDER”, place a “builder trace path from mark” after the “repeat”
loop.
Step 28: Using the drop-down menu in “builder trace path from mark”, select an Oak
Fence.
Step 29: Now, open a Flat World in the Minecraft game, and type “pen” in the chat
window. You should see a pen being built all the way around you! For an extra
challenge, you might try to get the Builder to add a fence gate
81 | P a g e
Step 30: Now comes the fun part. The array is loaded up with animals, the pen has
been built… it’s time to let them loose! For this command, we will simply go through
the entire array and for each animal in the array, we will spawn two of them a few
blocks away from you but still within the pen.
Step 31: From “PLAYER”, get an “on chat command” and rename it “zoo”.
Step 32: From “LOOPS”, drag a “for element” into your “on chat command "zoo"”.
Step 33: In the “for element”, use the drop-down menu for the 2nd slot to select
animalarray.
82 | P a g e
Step 34: From “MOBS”, drag a “spawn animal” block and place it inside “for element”.
Step 35: From “VARIABLES”, drag the value variable into the “spawn animal” block, replacing the
default chicken animal.
Step 36: Adjust the coordinates in “spawn animal” to (~3, ~0, ~0), so the animals will spawn a
few blocks away from the Player.
Step 37: To create pairs of animals, right-click on the “spawn animal” block to Duplicate it. You
could also use a loop here if you choose.
Step 38: Go back into your Minecraft world, and type the command “zoo” into the chat window,
and watch the animals appear!
83 | P a g e
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
84 | P a g e
Consider an Array with variables of
Integer Data Type stored in it.
Below is the diagram that displays how
This array can be declared in following data and indexes are structured in such
format: an Array:
Once you complete this exercise, your final output should look as shown in the below
screenshot:
Let us now follow below step by step procedure to replicate this output on our screen:
85 | P a g e
86 | P a g e
87 | P a g e
88 | P a g e
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 (https://code.org/)
89 | P a g e
4.9 Examples of arrays using Arcade
Example 1: Printing the first element of the array
90 | P a g e
Example 3: Adding an element in an array
91 | P a g e
there is a limitation on what can be to the original after you finish iterating
modified in a collection. As we have read the collection.
above, modifying a collection's elements
while iterating through that collection is
not allowed and throws an error in the Removing Elements During Iteration
program. We cannot directly add or
remove elements while iterating through To remove elements from a list, you can
the collection that includes them. create a new list, then insert the
elements you wish to keep. Or, add the
Below are certain points that we need to elements you wish to remove to a
note about collections: different list and remove them after you
finish iterating the collection.
• Collections that do not support
modification operations (such
as add, remove and clear) are
known as “unmodifiable”.
Collections that are not
unmodifiable are modifiable.
• Collections which guarantee
that no change in the
Collection object will be visible,
are known as immutable.
Collections that are not
immutable are mutable.
• Lists assure that their size
remains constant even though
the elements can change are
known as fixed size. Lists that
are not fixed-size are referred
to as variable-size.
• We cannot iterate or modify a
Collection that is null.
92 | P a g e
4.12 Quiz Time
Option 1 -1
Option 2 1
Option 3 2
Option 4 0
Answer: Option 4
Question 3 An array is
93 | P a g e
Standard Questions
1. Draw a flowchart for the optimized algorithm for finding the square of numbers
that we learnt in this chapter
Teacher’s Note: The teacher should explain to the students the above problem with
the help of pseudocode to understand it and write the corresponding flowchart. The
teacher should encourage the students to do the problem on their own.
Teacher’s Note: The teacher should explain to the students the logic used to find the
prime number. The teacher should encourage the students to think about how this
logic can be written in the program. Logic and solution can be different for each
student.
Applied Project
Create an exercise in Minecraft to create and Arrays of even numbers from 1 to 20 and
then iterate over each element of this Array.
Teacher’s Note: The teacher should explain to the students the project to understand
it and write the corresponding block code for creating an array of even numbers. The
teacher should encourage the students to do the problem on their own. The logic will
be different for all the students.
94 | P a g e
4.13 What have you learnt in this chapter?
By now you:
• Should know what arrays are and their practical implementations
• Should know about collections
95 | P a g e
HELLO WORLD WITH CODE
also ask the students to come up with
such examples to encourage critical
5.1 Lesson Structure
thinking.
1. What is a programming
language? Activity: Place students in groups of
2. Activity – Sorting the list three or four and guide them through
3. Getting used to syntax the exercises
4. What are variables and data types For the exercise section, the teacher
in programming? should make sure that the children are
5. Activity – Building a calculator comfortable with the Make Code platform
6. Quiz Time and they have it working on their
computers. The practice challenges can
be solved in several ways and do not
5.2 Lesson Plan have a definite answer.
Subtopics Number Method
Assignment: Allow students to
of
perform at least one practice exercise
Periods
What is a 3 Theory on their own
programming The teacher should encourage students
language? to come up with unique solutions to the
What are Theory challenges to test their creativity and
variables and
understanding of the subject.
data types in
programming?
Activity – Practical
5.4 What will you learn this
Building a
Calculator chapter?
Quiz Time 2 Practical
96 | P a g e
A computer program is a set of
instructions that is given to a computer
Programming languages are of two
to execute. A programming language is a
types, high-level languages and low-level
tool we use to write instructions for
languages. Both high-level and low-level
computers to follow.
languages have their own applications,
We need a programming language since so it is important to understand the
computers cannot understand the difference between the two types of
languages we speak. Computers can languages.
only understand binary strings of 1s and
A low-level programming language is one
0s.
that is made to be easily understood by
The very earliest computers were the computer. They include machine
programmed by changing ones and code and assembly language, both of
zeros manually, alternating the circuit which instruct computer hardware
and the wiring. All modern programming components to carry out instructions
languages, however, are made up of a directly. However, low-level
series of syntax and symbols that act as programming languages are difficult to
a bridge that allows humans to translate learn and time-consuming to code.
their thoughts into instructions that
computers can understand. A high-level programming language is
made to help human programmers
Over the years, thousands of communicate easily to the computer.
programming languages have been Good examples of high-level
created, and more are being created programming languages include C,
every year. Some of the most popular Java, Python. These languages are
programming languages are Python, usually compiled or converted into low-
JavaScript, Java and C++. Later in this level programming languages so that
chapter, we will look at some of the basic they can be executed directly. The
syntax of Python. person who invented the concept of a
compiler was Grace Hopper, sometimes
Low Level vs High Level Programming
called "Amazing Grace".
Language
97 | P a g e
Hence, once you spot the smallest number from the list, you swap it with the number
which was present at the top position in the unsorted list.
Now, the first row from our list is sorted. We will sort the second row now. We will repeat
the similar technique here. We will find the smallest number from the remaining
unsorted list and swap it with the number in second row.
We will repeat this process till we reach the last row from the list. When you are done
with the last element from the list you can look back and check that all the numbers
from the list are now sorted and our list is now ordered in ascending order.
This method of sorting in programming is called as “Selection Sort”.
Let us now sort the below array in ascending order using selection sort algorithm:
Array = {3, 2, 11, 7}
98 | P a g e
Step 1: For i = 0
Step 2: For i = 1
Step 3: For i = 2
99 | P a g e
Step 4: For i = 3
100 | P a g e
5.8 What are Variables and longer string. To concatenate strings, we
Data types in use a + symbol between the two strings.
programming? Let’s look at the syntax for these
operations.
101 | P a g e
• Subtraction 3. Performing Multiplication of
• Multiplication Integers and Floats
• Division
• Modulus (Remainder)
x = 1
Now that we know what Integers and
Floats are, let us now understand the y = 2
syntax for performing different
Mathematical operations on them in our multiplication = x * y
Program:
1. Performing Addition of Integers 4. Performing Division of Integers
and Floats and Floats
x = 1 x = 1
y = 2 y = 2
sum = x + y division = x / y
2. Performing Subtraction of
Integers and Floats
5. Performing Modulus of Integers
x = 1 and Floats
y = 2 x=1
subtraction = x - y y=2
modulus = x % y
Now that we are familiar with various arithmetic operations, in the next exercise, we will
get to understand more on this topic.
To understand these operations better, let us now perform the below activity. You need
to open MakeCode editor for this activity.
102 | P a g e
103 | P a g e
104 | P a g e
105 | P a g e
106 | P a g e
107 | P a g e
Note: Arcade 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
Option 1 string
Option 2 integer
Option 3 float
108 | P a g e
Option 4 All the above
Answer: Option 4
109 | P a g e
Option 4 Medium Language
Answer: Option 3
2. Write an algorithm to sort the below list in descending order using Selection Sort
Technique:
[10, 21, 45, 67, 12]
Teacher’s Note: The teacher should hint students the logic that can be applied to
solve this problem. This will help students to understand it and write the
corresponding algorithm. The teacher should encourage the students to do the
problem by their own.
Applied Project
Teacher’s Note: The teacher should explain the students the project so that they can
understand it and write the corresponding block code to perform modulus operation
110 | P a g e
on two variables. The teacher should encourage the students to do the problem by
their own. The logic will be different for all the students.
111 | P a g e
REFERENCES
Microsoft. 2021. Microsoft MakeCode for Minecraft. [Online]. [25 February 2021].
Available from: https://minecraft.makecode.com
ACM, Inc. 2021. Code of Ethics. [Online]. [25 February 2021]. Available from:
https://www.acm.org/code-of-ethics
Association for computing machinery (acm). 2016. CSPathsala. [Online]. [16 March
2021]. Available from: https://cspathshala.org
112 | P a g e