67% found this document useful (3 votes)
3K views

ClassVII Coding Teacher Handbook

This document is an introduction to coding handbook for grade 7 teachers. It includes acknowledgements, an introduction about the purpose of introducing coding in grades 6-8, and a table of contents that outlines the chapters in the handbook which cover topics like variables, sequencing, functions, arrays and collections. The handbook aims to enable students to acquire early coding skills through a gamified learning approach using block and text-based coding platforms.

Uploaded by

manan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
3K views

ClassVII Coding Teacher Handbook

This document is an introduction to coding handbook for grade 7 teachers. It includes acknowledgements, an introduction about the purpose of introducing coding in grades 6-8, and a table of contents that outlines the chapters in the handbook which cover topics like variables, sequencing, functions, arrays and collections. The handbook aims to enable students to acquire early coding skills through a gamified learning approach using block and text-based coding platforms.

Uploaded by

manan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 121

INTRODUCTION

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

Editorial and Creative Inputs


• Mr. Manuj Ahuja, IAS, Chairperson, Central Board of Secondary Education

Guidance and Support


• Dr. Biswajit Saha, Director (Skill Education & Training), Central Board of
Secondary Education
• Dr. Joseph Emmanuel, Director (Academics), Central Board of Secondary
Education
• Sh. Navtez Bal, Executive Director, Public Sector, Microsoft Corporation India
Pvt. Ltd.
• Sh. Omjiwan Gupta, Director Education, Microsoft Corporation India Pvt. Ltd.
• Dr. Vinnie Jauhari, Director Education Advocacy, Microsoft Corporation India
Pvt. Ltd.
• Ms. Navdeep Kaur Kular, Education Program Manager, Allegis Services India

Value adder, Curator and Co-Ordinator


• Sh. Ravinder Pal Singh, Joint Secretary, Department of Skill Education, Central
Board of Secondary Education
ABOUT THE HANDBOOK

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.

Therefore, CBSE is introducing ‘Coding’ as a skill module of 12 hours duration in classes


VI-VIII from the Session 2021-2022 onwards. The idea is also to simplify the coding
learning experience by nurturing design thinking, logical flow of ideas and apply this
across the disciplines. The foundations laid in the early years will help the students to
build the competencies in the area of AI, data sciences and other disciplines.

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

Minecraft education edition


Minecraft education edition is a game-based learning platform that promotes creativity,
collaboration, and problem-solving in an immersive digital environment. This platform
provides a fun way of learning coding and design thinking concepts.
Visit https://education.minecraft.net/ for more details.

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

Ethical practices in coding ...............................................................................1


Variables in Real Life ......................................................................................2
1.1 Lesson Structure ................................................................................2
1.2 Lesson Plan .......................................................................................2
1.3 Teacher’s Notes...................................................................................2
1.4 What will you learn in this chapter? .......................................................2
1.5 What is Variable Initialization? ..............................................................3
1.6 Data Types in programming ..................................................................7
1.7 How do we validate user input in programming? .......................................7
1.8 Math Operations in Programming...........................................................8
1.9 Quiz Time ..........................................................................................9
1.10 What have you learnt in this chapter? ................................................ 11
Sequencing with Block Coding........................................................................ 12
2.1 Lesson Structure .............................................................................. 12
2.2 Lesson Plan ..................................................................................... 12
2.3 Teacher’s Note .................................................................................. 12
2.4 What will you learn in this Chapter? ..................................................... 13
2.5 Recap of Loops ................................................................................. 13
2.6 What is Sequencing? ......................................................................... 13
2.7 Examples of Sequence, Selection and Iteration ....................................... 14
2.8 What is a Bug? ................................................................................. 16
2.9 Activity Drawing Rectangle.................................................................. 16
2.10 Fun Activity: Chase the Apple ........................................................... 22
2.11 Types of Loops ............................................................................... 32
2.12 Apply Loops and Conditionals with sequencing .................................... 32
2.13 Is there a better way to apply sequencing? .......................................... 33
2.14 Activity: Distributing Birthday Sweets ................................................ 37
2.15 Quiz Time ..................................................................................... 38

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.

Be honest and trustworthy


2. As you keep building software of your own, ensure you provide full disclosure of all
software capabilities, constraints, and possible problems
3. Do not provide misleading claims about the capabilities of the software
4. Always be honest about your qualifications and competence to perform a task.
5. Try your best to adhere to commitments you have made
Give proper credit to another person’s work

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.

1.3 Teacher’s Notes


1.4 What will you learn in this
chapter?
Discuss: What is Variable
This chapter aims at teaching students
Initialization?
how variables can be used in real life. We
The teacher should introduce variable will learn how to initialize variables in
initialization to the students. They can programming, how to validate user input
also ask the students to come up with and performing mathematical
such examples to encourage critical operations of different data types.
thinking.
Discuss: Different Math Operations in
Programming

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.

In programming, a variable can be


initialized using the below syntax:
Datatype VariableName = Value;
You cannot take any action on any
variable till the time you initialize it.
However, you can initialize the value of
a variable to null. Do not confuse the
value of null to variable that is not
initialized. “Null” is still a value, a
variable that is not initialized does not
hold any value, not even null.
Note: In some programming languages
like python, there is no command to
declare variables. A variable is created
the moment you first assign a value to it.

Example of declaring variables in


python
a=5

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

Objective Type Questions

Question 1 Process of assigning value to a variable before it is being used is


called:
Option 1 Initialization
Option 2 Operation
Option 3 Realization
Answer: Option 1

Question 2 int k1, k2 = 23 is an example of:

Option 1 Variable declaration


Option 2 Adding values in a function
Option 3 None of them
Answer: Option 1

Question 3 Which of the following is NOT a correct variable name?


Option 1 2bad
Option 2 Zero
Option 3 theLastValueButOne
Option 4 Year2000
Answer: Option 1

Question 4 Which of the following declarations is NOT correct?


Option 1 Double duty;
Option 2 Float loan = 12.3;
Option 3 Boolean value = 21;
Option 4 Int start = 45, end = 99;
Answer: Option 3

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

Question 6 What is an expression?


Option 1 The same thing as a statement
Option 2 An expression is a list of statements that make up a program
Option 3 An expression is a combination of literals, operators, variables, and
parentheses used to calculate a value
Option 4 An expression is a number expressed in digits.
Answer: Option 3

Question 7 What is the value of the following expression?


(2 - 6) / 2 + 9
Option 1 7
Option 2 8
Option 3 9
Option 4 10
Answer: Option 1

Standard Questions

1. What is variable initialization?


2. What is the syntax to initialize a variable in programming?
3. Why do you think validating user input is important in programming?
4. What are your opinions on naming convention of variables declared in
programming? Write down five best practices that you think one should follow
while declaring variables.

Higher Order Thinking Skills (HOTS)

1. Write a program to check if a String is palindrome or not.

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

Create a program in Arcade to display square of numbers from 1 to 10

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.

1.10 What have you learnt in this chapter?

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.

2.2 Lesson Plan Discuss: How to apply the concept of


sequencing in Loops and
Subtopics Number Method Conditionals?
of
Periods The teacher should introduce the concept
What is 2 Theory of sequencing using Loops and
Sequencing? Conditionals to students with examples.
Activity: Drawing Practical They should ensure that the children are
a Rectangle in not confused with these terms and
Minecraft explain the pseudo code to the students
Quiz Time Practical
to improve their conceptual
How to apply Theory
understanding.
concept of
Sequencing in Activity: Place students in groups of
Loops and three or four and guide them through
Conditionals? the exercises
Activity: Making Practical
a Square in For the exercise section, the teacher
Minecraft using should make sure that the children are
Loops comfortable with the Make Code platform
Practice 1 Practical and have it working on their computers.
Assignment 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

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

Step 3: temp = num1


Step 4: num1 = num2
Step 5: num2 = temp

Step 6: PRINT num1, num2


Step 7: Stop

Over here, to reach the final output, you


need to follow the algorithm step by step.

First, Read the two numbers that needs


to be swapped. Then, assign value of
num1 to a temporary variable called
“temp”. Next, assign value of num2 to
num1. Later, assign value of “temp” to
num2. Finally, Print the values of num1
If you do these steps in any other order, and num2 which are now swapped.
would the result still be a sandwich? No!
Point to be noted over here is that the
Similarly, in programming, tasks need to steps that followed to achieve this
be done in the correct sequence to get output are in a sequence. Skipping any
the desired output. step from this sequence or altering the
sequence will lead to errors in the
In both daily tasks and coding, if we
program or generation of wrong output.
don’t put every step in the right
sequence, the result will not be what we This is how sequencing in programming
wanted. Sequencing is a foundational works.
concept in programming, and everything
we learn in the future will build on this Now let us understand the concept of
Selection using an example.
concept.
Take a look at below pseudocode to
check if age entered by the user is of a
senior citizen or not. Consider that

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.

As you can see in the flow chart the flow

int age = 61;


if (age>=60)

print(“Person is a senior
citizen”);

else
print(“Person is not a senior
citizen”);

Over here, the pseudocode is trying to


check if the age defined in the program
if of a senior citizen or not.
If you follow the sequence of
pseudocode, you will see that the
program makes a “selection” of which
flow to enter depending on the age
defined in the program.
If the age is more than or equal to 60,
the program enters the if block. If the age
is less than 60, the program enters else
block. of the program will repeat or iterate for
each number from 1 to 100. For every
This is how concept of selection is single iteration it will check for the
applied in programming. condition and take the appropriate
Moving forward, let us have a look at workflow. This is how iteration works in
example of Iteration. programming. It will repeat the block of
code for multiple times till the specified
In programming, loops follow the condition is achieved.
iteration depending on the condition.
Every loop iterates at least once if not
more.
Consider a program to print all the
natural numbers from 1 to 100. It will

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.

2.9 Activity Drawing Rectangle

Let us now understand sequencing with another example.


What would be the steps to draw a rectangle of length 5 cm and height 3 cm on your
screen?

First, draw a line 5 cm in length


Then turn the cursor right by 90 degrees

Then draw a second line 3 cm in length


Then turn right by 90 degrees

Then draw a third line 5 cm in length


Then turn right by 90 degrees

Then draw a fourth line 3 cm in length

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/).

2.10 Fun Activity: Chase the Apple

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

First, create a new project as shown below.

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.

Now let us see how we can combine all


the three building blocks of algorithms –
Nested Loops sequencing, selection, and iteration.
Any loop in program may contain In real life, complex algorithms can have
another loop inside it. When there is a hundreds, if not thousands, of steps in
loop inside another loop, it is called as a
a sequence. However, often while

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?

2.13 Is there a better way to apply sequencing?

Activity: Better way to create a square

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/).

2.14 Activity: Distributing Birthday Sweets

In this activity, we will learn about iteration.


It is Arun’s birthday today. The entire class wishes birthday to Arun. Later, Arun takes
out the sweets from his bag and starts distributing it to the students of the class.
Take a look at flowchart in Fig 1.0 understand how Arun uses concept of iteration while
distributing birthday sweets with the class.

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.

2.15 Quiz Time

Objective Type Questions

Question 1 What is a bug in programming?


Option 1 A feature in a program that causes it to run correctly
Option 2 A feature in a program that can predict output.
Option 3 A feature in a program that generates incorrect output.
Option 4 All the above
Answer: Option 3

Question 2 What is sequencing in programming?

Option 1 A programming structure, where steps are performed in an order.


Option 2 A programming structure, that repeats itself until a condition is met.
Option 3 A feature in a program that generates incorrect output.
Option 4 All the above
Answer: Option 1

Question 3 What is looping in programming?

Option 1 A programming structure, where steps are performed in an order.


Option 2 A programming structure that repeats itself until a condition is met.
Option 3 A feature in a program that generates incorrect output.
Option 4 All the above
Answer: Option 2

38 | P a g e
Question 4 What is selection in programming?

Option 1 A list of instructions which are followed in a set order


Option 2 A list of instructions where there is a choice based on a condition
Option 3 A list of instructions which will loop based on a condition
Option 4 A list of instructions that will loop forever
Answer: Option 2

Question 5 What is iteration in programming?

Option 1 A list of instructions which are followed in a set order


Option 2 A list of instructions where there is a choice based on a condition
Option 3 A list of instructions which will loop based on a condition
Option 4 A list of instructions that will loop forever
Answer: Option 3

Standard Questions

1. Explain what an algorithm is with the help of an example.


2. Explain a bug in any program/application that you have encountered in real
life.
3. Explain if sequencing, selection and iteration can be used together? Support
your answer with a proper explanation.
4. Explain three examples where you can apply loop and conditionals to simplify
sequencing

Higher Order Thinking Skills (HOTS)

1. Write an algorithm to print cube of numbers from 1 to 10.

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.

2.16 What have you learnt in this chapter?

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.

3.4 What will you learn in this


chapter?
At the end of this chapter, you will
understand the use of functions in
programming. You will know:

• Usefulness of using functions


in code.
• How to define and call a
function.
• Parameters in a function.
• Different type of values
returned by a function.

3.5 What exactly are


Functions?
What do you think of when you hear the
word pattern? Well, a pattern is one
when something or a series of things are
repeated in sequence. We all may have
seen patterns before, like in color arts,
music or even mathematics.
Similarly, there can be patterns in code
too. As a programmer, there will be times
when you want the computer to repeat
the certain lines of code in sequence. If
there is a block of code that you want
your computer to repeat lots of times,
the tool that you may want to use is a
function.

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

Although the action “Drink water”


constitutes of 4 steps, yet while
3.8 How to reduce redundancy
describing our day today life routine to
using Functions? someone else, we use the phrase like
To illustrate this, let us take a very basic “Drink water”. This action of “Drink
human habit of drinking water. water” is easy for the other person to
understand and covers up the above 4
If we look at the action of drinking water, steps in a single action. Thus, every time
it involves 4 main steps only: we include “Drink water” in our routine,
• Take a glass of water. it will automatically cover the above 4
• Sip the water from the glass. steps.
• Gulp the water down the throat. Similarly, the main idea behind using a
• Put down the glass when we are function in your code is to keep the code
no longer thirsty. DRY (Don’t Repeat Yourself). Cutting

48 | P a g e
out repeated commands helps to
minimize errors, keeps code short, and
saves programming time.

3.9 Advantages of using


Functions
Few of the advantages of using functions
are: Similarly, if we want to calculate the
area of a rectangle, we need to know the
Increases readability makes code
organized and easy to understand. length and breadth of the rectangle.
Here too, the formula for calculating the
Reduces code length: redundant code area of the rectangle always remains the
is removed and replaced by functions. same.
Reusability: Code reusability increases. So, in the above-mentioned scenarios, if
we consider the task of calculating the
area of circle & square as functions
3.10 What are different respectively, then the formulae used to
Function Parameters? calculate the area can be considered as
the body of the function. However, to get
a concrete value from the functions, we
Consider a problem statement, where we need to provide the value of radius in
are required to calculate the area of a case of calculating the area of a circle &
circle. To do so, we need to know the the value of length & breadth to
radius of the circle whose area we are calculate the area of the rectangle.
required to calculate.
Thus, the variables accepted by a
However, the formula for calculating the function to perform the set of tasks
area of a circle always remains the same. defined in its body are called function
parameters.

3.11 Activity – Finding the square of a number

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

3.12 Activity – Arranging the Books

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.

1. You can arrange them from tallest height to smallest.


2. You can arrange them alphabetically.
3. You can arrange them by the frequency in which you use them.
The ways of arranging that we just listed down, is called as “Sorting” in programming.

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:

1. Sorting a collection helps you answer questions like “which is the


tallest/smallest/fastest item in this collection?”
2. Arranging things in order can make other algorithms work better.

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/

First, create a new project, as shown below.

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

3.14 Can Function return a value?

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

3.15 What is an event?

An event is something that happens. In


the context of coding, events are a 3.16 What is an event handler?
generalization of all the things that the
program can respond to.

Some common examples of event An event handler is a piece of code


include: associated with an event in the code. An
event handler gets executed, when that
1. Clicking on the button of a web event occurs. For example, in MakeCode
page platform if you want a player to move
2. A web browser fully loading a web forward when the user clicks on the
page forward icon you would create a code
3. Key press inside a desktop block like below.
application

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.

3.17 Quiz Time

Objective Type Questions

Question 1 Function in a program decreases readability


Option 1 True
Option 2 False
Answer: Option 2

Question 2 Function in a program increases code reusability


Option 1 True
Option 2 False
Answer: Option 1

Question 3 Functions in programming help in reducing code redundancy


Option 1 True
Option 2 False
Answer: Option 1

70 | P a g e
Question 4 A function can return a value
Option 1 True
Option 2 False
Answer: Option 1

Question 5 What do we call the variables found in the definition of the


function on which further operations may be performed?
Option 1 Return value
Option 2 Parameter(s)
Option 3 Data types
Option 4 None of the above
Answer: Option 2

Standard Questions

1. Explain five advantages of using functions.


2. What are function parameters?
3. Explain how functions help in reducing redundancy of code.
4. Can functions return a value? Support your answer with proper explanation.
5. Name three scenarios where using functions will help you reduce redundancy of
code
6. Explain parameterization of functions. Where can and why do you think
parameterization is useful?
7. Explain what the output of below program will be:

71 | P a g e
def test(x, y):

if x > y:
return y

def test1(x, y, z):


return test(x, test(y, z))

print(test1(2, 7, -1))

Answer: -1

8. Find an error in the below program:

def sum(numbers):
total = 0
for x in number:

total += x
return total

print ( sum ( ( 1 , 2 , 3 , 4 , 5 ) ) )

Answer: Variable “number” is not defined anywhere in the program.

Higher Order Thinking Skills (HOTS)

1. Write a function to print even numbers from 1 to 50

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

The practice challenges should be done on the Minecraft platform.


1. Create a block code which takes radius and height of a cylinder as input to a
function and computes its volume. The volume computed should be returned by
the function.

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

Activity: Place students in groups of


three or four and guide them through
4.1 Lesson Structure
the exercises
1. What are Collections?
2. How exactly can we iterate over For the exercise section, the teacher
Collections? should make sure that the children are
3. Modifying Collections comfortable with the Make Code platform
4. Quiz Time and they have it working on their
computers. The practice challenges can
be solved in several ways and do not
4.2 Lesson Plan have a definite answer.

Subtopics Number Method Assignment: Allow students to


of perform at least one practice exercise
Periods on their own
What are 3 Theory
Collections? The teacher should encourage students
How exactly can Theory to come up with unique solutions to the
we iterate over challenges to test their creativity and
Collections? understanding of the subject.
Modifying Practical
Collections
Quiz Time 2 Practical 4.4 What will you learn in this
chapter?

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

4.6 Activity – Algorithm for a done


perfect square return false
end
square, and false if it is not a perfect
In this activity, we will learn to write an square.
algorithm for finding if a number is a
perfect square.
To start with let us take a look at Can you think of ways to improve the
following questions: algorithm?
Have a look at below optimized
algorithm.

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.

4.7 Activity Building a Zoo

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

Arrays improve readability of code by


4.8 What are Arrays? using a single variable for a large set of

An Array is a collection of similar data Limitation of Arrays


type variables. Arrays do not support
• You can only store variables
different data types in same collection. with same data types in an
For example, you can make an Array of
Array
Integers as well as another Array of • The variables in an Array are
Strings. However, you cannot make an always ordered sequentially
Array having Integer and Strings in with index starting with 0
same Collection.
In real world, you can consider books in
a library to be the example of arrays
data. However, there are following
where all the shelves have a common
limitations that we need to note while
data type (read – book) in it.
using Arrays.

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:

arr = [10, 20, 30, 40, 50, 60];


Using the above syntax, we can deduce
that an array named “arr” is declared
with data type as integer i.e this array
can only hold integer values. We have
initialized this array with six values i.e
10, 20, 30, 40, 50, 60.
Now, let us try to implement similar example using Minecraft Platform. Next exercise
will help you understand step by step how to create an Array and calculate its length
using Minecraft.

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

Example 2: Calculating the sum of the elements in an array

90 | P a g e
Example 3: Adding an element in an array

4.10 How can we iterate over However, modifying a collection's


collections? elements while iterating through that
collection is not allowed and throws an
error in the program. We cannot directly
As we have understood so far, add or remove elements while iterating
Collections can consist of lists, sets, or through the collection that includes
maps. There is a lot of data that we can them.
store in collections. Naturally, we need
to use this data or perform modifications
on this data depending on the program 4.11 Modifying Collections
requirement. To do this, we need to
iterate through the data that is stored in
these collections. This is where the Now that we have learnt what are
concept of Iterator comes into the collections, how do we store data in
picture. collections and iterate over the data,
next question that may come to your
The iterators are used to provide users a mind is how do we modify this data that
uniform way of accessing collections in a
is stored in the collection?
sequential manner. Whatever type of
collection we are using, we always need
to traverse through the elements of these
Programming facilitates multiple ways of
collections to fetch the data or make any
modifying the data stored in collections.
modifications to that data.
Not every collection can be modified and

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.

Let us now understand the


modifications that we can do on
collections.

Adding Elements During Iteration

To add elements while iterating a list, set


or map, keep the new elements in a
temporary list, set, or map and add them

92 | P a g e
4.12 Quiz Time

Objective Type Questions

Question 1 What is the starting index of an array?

Option 1 -1
Option 2 1
Option 3 2
Option 4 0
Answer: Option 4

Question 2 Which one is an incorrect array?

Option 1 Arr[] = [‘a’ , ‘b’ ,’c’ ,’d’]


Option 2 Arr[] = [1 , 2 ,3 ,4]
Option 3 Arr[] = [1, ‘a’, ‘b’, 2]
Option 4 Arr[] = [2.0 , 9.4, 5.6 , 6.7]
Answer: Option 3

Question 3 An array is

Option 1 A group of elements of same data type


Option 2 A type of collection that contains more than one element
Option 3 A type of collection in which elements are stored in memory in
continuous or contiguous locations
Option 4 All of the above
Answer: Option 4

Question 4 Select a correct statement about Arrays


Option 1 An array address is the address of first element of array itself
Option 2 An array size must be declared if not initialized immediately
Option 3 Array size is the sum of sizes of all elements of the array
Option 4 All of the above
Answer: Option 4

93 | P a g e
Standard Questions

1. What are collections?


2. How can we iterate over collections?
3. What are the different types of modifications that we can perform on
collections?
4. What is an Array Index?
5. Do collections allow backward traversing of data? Support your answer with a
proper explanation.
6. Name three real life collections which work like Arrays.

Higher Order Thinking Skills (HOTS)

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.

2. Write a program to create an array of prime numbers from 50 to 100.

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

At the end of this chapter, you will


understand the basics of a programming
5.3 Teacher’s Notes language.
Discuss: What is a programming
language?
5.5 What is a Programming
The teacher should introduce the concept Language?
of programming language to the students
by using real-life examples like those
mentioned in the curriculum. They can

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

5.6 Activity – Sorting the list

We will learn the concept of Selection Sort in this activity.


Suppose we have a list of unsorted numbers. Over here we want to sort the list in a way
that smallest number is on top of the list and largest number is at the bottom.
We start with finding the smallest number from the list. Once we find this number, we
want to put it at the top of the list. However, if you put this number on the top of the
list, where should the number who currently is on the top of the list be shifted to? You
do not have any additional space here.

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”.

The algorithm for Selection Sort is as stated below:

Step 1: Set MIN to location 0

Step 2: Search the minimum element in


the list
Step 3: Swap with value at location MIN
Step 4: Increment MIN to point to next
element
Step 5: Repeat until list is sorted

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

The loop gets terminated as “I” becomes 2.


The final state of array after loop is terminated looks like below:

You will be surprised to know that some


5.7 Getting used to syntax of the world’s most famous websites like
Google, YouTube and Instagram use
Python!
Python is an easy to learn programming Now let us get started with some basic
language that can be used to build a Python syntax.
variety of applications. Python is used in
web development, game development
and development of desktop-based
applications. Python is also widely used
for data science, machine learning and
artificial intelligence.

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.

Defining a variable ‘Text’ and setting its


value.
Variables are used by programmers to
store values. Whenever a variable is Text = “This is a string variable.”
created, Python assigns a spot to it so
2. Accessing the first letter of the
that its value can be stored till the
‘Text’ variable. The value printed will be
program runs. We can store lots of
T.
different types of information in a
variable. For example, we can store a print(Text[0])
number, text, or a list of items. We can
3. Defining a second variable ‘Text2’
also change the value assigned to a
and joining it to ‘Text’. The value printed
variable while the program is running.
will be “This is a string variable. This is
Variables are useful for several purposes a second variable.”
like counting how many times an event
Text2 = “This is a second variable.”
occurs, saving inputs from users, and
performing complex calculations. print (Text+Text2)
In any programming language, a Integers and Floats
variable can only store a value that is in
a format. These formats are called data In Python, integer variables are used to
types. Python also has several in-built store whole numbers, which can be
data types. First, let us understand positive or negative. Quotation marks
three basic data types in Python - string, should not be used while defining
integer and Boolean. integers. Integer variables can be treated
like numbers for all mathematical
Strings operations.
In Python, a string is defined as a If you need to store decimal numbers in
sequence of characters enclosed in Python, you should use float variables
either single or double or triple quotes. as integer variables ignore the decimal
part of a number. When you combine a
The characters can be alphabets of any
float variable and an integer variable in
language or symbols. Strings are also
a mathematical calculation, the
called str in short.
resulting answer will always be a float.
You can perform many different You can do several arithmetic operations
operations on strings. You can access with floats and integers. Let us see some
each character in a string using its common operations with floats and
position in the string. You can also join integers.
two or more strings together to create a
• Addition

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.

5.9 Activity: Building a Calculator

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

5.10 Quiz Time

Objective Type Questions

Question 1 Low level languages are user friendly


Option 1 True
Option 2 False
Answer: Option 2

Question 2 Which of the following is a valid data type?

Option 1 string
Option 2 integer
Option 3 float

108 | P a g e
Option 4 All the above
Answer: Option 4

Question 3 Which of the following is a valid arithmetic operation?


Option 1 Addition
Option 2 Multiplication
Option 3 Modulus
Option 4 All the above
Answer: Option 4

Question 4 Which of the following is NOT a string type?


Option 1 character = “Mr.”
Option 2 vehicle = “Truck”
Option 3 speed = 70
Option 4 lives = “12”
Answer: Option 3

Question 5 In computer science, variables:


Option 1 are number like Pi
Option 2 represent parts of an experiment that are measured or tested
Option 3 are placeholders for storing information
Option 4 are unchangeable
Answer: Option 3

Question 6 Translator which is used to convert codes of assembly language into


machine language is termed as
Option 1 Assembler
Option 2 Attempter
Option 3 Compiler
Option 4 Debugger
Answer: Option 3

Question 7 Language in which single statements can be written to accomplish


substantial tasks is termed as
Option 1 Machine Language
Option 2 Assembly Language
Option 3 High Level Language

109 | P a g e
Option 4 Medium Language
Answer: Option 3

Short Answer Questions

1. What are High Level and Low-Level Languages in Computers?


2. What is the Syntax to declare a String variable in Python?
3. What are different Mathematical Operations that we can perform on variables in
Python?
4. Explain different data types used in Python with the help of its syntax
5. Explain what variables are and why are they used in programming
6. Research and name five programming languages. Categorize them in the buckets
of high-level programming language and low-level programming language
7. Give one example where you can use mathematical operators in Python to build
a program that will help you in day to day chores.

Higher Order Thinking Questions(HOTS)

1. Draw a flowchart to explain the flow of selection sort technique in programming.


Teacher’s Note: The teacher should explain the student’s selection sort with the help
of pseudocode so that they can understand it and draw the corresponding flowchart.
The teacher should encourage the students to do the problem by their own.

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

Create a program in Arcade to perform Modulus operation on two variables.

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.

5.11 What have you learnt in this Chapter?

This chapter gave us a basic overview of creating a program in Python.

• We have learnt about high and low-level programming


• We have also learnt about the syntax in python and
variables and data types.
• We also performed a fun activity to create a Calculator
in Arcade.

111 | P a g e
REFERENCES

Microsoft. 2021. Microsoft MakeCode Arcade. [Online]. [25 February 2021].


Available from: https://arcade.makecode.com

Microsoft. 2021. Microsoft MakeCode for Minecraft. [Online]. [25 February 2021].
Available from: https://minecraft.makecode.com

Microsoft. 2021. Computer Science Subject Kit | Minecraft: Education Edition.


[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

Association for computing machinery (acm). 2016. CSPathsala. [Online]. [16 March
2021]. Available from: https://cspathshala.org

112 | P a g e

You might also like