ClassVII Coding Student Handbook
ClassVII Coding Student Handbook
TO CODING
GRADE VII
Student Handbook
Version 1.0
INTRODUCTION
TO CODING
GRADE VII
Student 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
CBSE acknowledges the initiative by Microsoft India in developing this coding handbook
for class VII students. 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
3.5 How to reduce redundancy using Functions? ......................................... 44
3.6 Advantages of using Functions ............................................................ 44
3.7 What are different Function Parameters? ............................................... 45
3.8 Activity – Finding the square of a number.............................................. 45
3.9 Activity – Arranging the Books ............................................................. 47
3.10 Activity: Calculating area of a circle ................................................... 48
3.11 Can Function return a value? ........................................................... 57
3.12 What is an event? ........................................................................... 65
3.13 What are Event Handlers? ............................................................... 65
3.14 Quiz Time ..................................................................................... 66
3.15 What have you learnt in this chapter? ................................................ 68
Understanding Arrays & Collections ................................................................ 69
4.1 What will you learn in this chapter? ..................................................... 69
4.2 What are Collections? ........................................................................ 69
4.3 Activity – Algorithm for a perfect square ................................................ 69
4.4 Activity Building a Zoo ....................................................................... 70
4.5 What are Arrays? .............................................................................. 77
4.6 Examples of arrays using Arcade ......................................................... 82
4.7 How can we iterate over collections? ..................................................... 83
4.8 Modifying Collections ......................................................................... 83
4.9 Quiz Time ........................................................................................ 85
4.10 What have you learnt in this chapter? ................................................ 86
Hello World with Code................................................................................... 87
5.1 What will you learn this chapter? ......................................................... 87
5.2 What is a Programming Language?....................................................... 87
5.3 Activity – Sorting the list..................................................................... 88
5.4 Getting used to syntax ....................................................................... 90
5.5 What are Variables and Data types in programming? ............................... 91
5.6 Activity: Building a Calculator ............................................................. 92
5.7 Quiz Time ........................................................................................ 98
5.8 What have you learnt in this Chapter? ................................................ 100
References ................................................................................................ 101
II
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
variable that is not initialized does not
1.1 What will you learn in this hold any value, not even null.
chapter? Note: In some programming languages
like python, there is no command to
This chapter aims at teaching students
how variables can be used in real life. We declare variables. A variable is created
the moment you first assign a value to it.
will learn how to initialize variables in
programming, how to validate user input
and performing mathematical
operations on different data types. Example of declaring variables in
python
2|Page
3|Page
4|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 (https://code.org/)
5|Page
Boolean data in Python is used to define
1.3 Data Types in Boolean variables. Boolean variables
programming can hold only two values in it, either
“true” or “false”.
Depending on the requirement,
programming languages offer wide
variety of data types to suit the 1.4 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 “false”. If the user input matches the
6|Page
expected input, you will reset the flag to note that subtraction can only be
true and execute. If the user value is set carried out on Integer, Float, Double
to false, you will abort the execution by datatypes only.
throwing an error message.
For example, if there are two integer
variables “a” and “b” declared in your
1.5 Math Operations in program. Where a = 3, and b = 2. If we
perform the subtraction operation of
Programming
these variables in programming, the
result is going to be 1.
Now that we have understood how to Multiplication
declare and initiate a variable and how
to validate the user input let us now Multiplication operation is used to
understand how we can perform perform the mathematical multiplication
mathematical operations of these of two variables. In programming, we
refer to “*” as a symbol of multiplication.
variables.
Please note that multiplication can only
In programming, there are following be carried out on Integer, Float and
operations that you can perform on Double datatypes.
variables.
Division
Addition
Division operation is used to perform
Addition operation is used to perform the mathematical division of two
mathematical addition of two variables. variables. In programming, we refer to
In programming, we refer to “+” as a “/” as a symbol of division. Please note
symbol of addition. Please note that that Division can only be carried out on
Addition can only be carried out on Integer, Float and Double datatypes.
Integer, Float, Double and String
datatypes only. You can use this Modulus
operator to concatenate two strings on Modulus operation is used to perform
either side of the operator. the mathematical remainder of two
variables. In programming, we refer to
For example, if there are two float “%” as a symbol of modulus. Modulus
variables, “x” and “y” declared in your operator divides variable on the left to
program. Where x = 1.1, and y = 2.2. If the variable on right and returns the
we perform addition operation these remainder. Please note that modulus
variables in programming, the result is can only be carried out on integer and
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 =
Subtraction operation is used to 10, and y = 3. If we perform modulus
perform mathematical subtraction of operation on these variables in
two variables. In programming, we refer programming, the result is going to be
to “-” as a symbol of subtraction. Please 1.
7|Page
1.6 Quiz Time
Option 1 2bad
Option 2 Zero
Option 3 theLastValueButOne
Option 4 Year2000
8|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;
Standard Questions
9|Page
Applied Project
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.
10 | P a g e
SEQUENCING WITH BLOCK CODING
order to complete a task or to solve a
2.1 What will you learn in this problem. There are three basic building
blocks that can be used when designing
Chapter?
algorithms:
1. What is sequencing? • Sequencing
2. Why is it important to follow a
• Selection
sequence in programming?
• Iteration
3. How to reduce steps in a
sequence with loops and These building blocks help us to convert
conditional operators? any complex problem into a well-defined
solution that can be understood and
implemented by others using
programming. For example, how would
2.2 Recap of Loops
you design an algorithm for your
1. In programming, repetition of a line morning routine?
or a block of code is also known as
iteration. • Wake up
2. A loop is an algorithm which • Brush your teeth
executes a block of code multiple • Take a bath
times till the time a specified • Have breakfast
condition is met. • Go to school
3. The break statement modifies the
normal flow of execution while it In this chapter, we will learn about the
terminates the existing loop and first building block of algorithms –
continues execution of the sequencing.
statement following that loop.
A sequence is a list of activities that are
4. Whenever a program encounters a
done one after another. Sequencing
continue statement, the control
refers to the specific order in which we
skips the execution of remaining
need to perform the activities in order to
statements inside the loop for the
get the desired output.
current iteration and jumps to the
beginning of the loop for the next Designing an algorithm for How to Make
iteration. a Sandwich
5. When there is a loop inside another
loop, it is called a nested loop.
11 | P a g e
Every day, we do many activities in a 2.4 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, look at the 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
12 | P a g e
considered a senior citizen if his age is follow the flow as shown in the Fig 2.1
above 60 years old. flowchart.
print(“Person is a senior
citizen”);
else
print(“Person is not a senior
citizen”);
13 | P a g e
2.5 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/
14 | 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:
15 | P a g e
Now follow the following steps
16 | P a g e
17 | P a g e
18 | P a g e
19 | 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
20 | P a g e
Now follow the steps mentioned below to create the game.
21 | P a g e
22 | P a g e
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
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 (https://code.org/)
29 | P a g e
success condition of outer loop triggers
Activity the inner loop which runs and reaches
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.
have a common side. Spawn 2 There is no restriction on how many
chickens in one square and 2 cows loops can be nested inside a loop.
in the other.
As we have studied, use of loops make Now, let us discuss the other two
our code manageable and organized. important aspects of an algorithm –
Mainly, there are three different types of selection and iteration.
loops:
Selection refers to the situation in which
the algorithm needs to make a choice
1. While Loop between two or more alternatives. It is
2. For Loop like asking questions like “Is it raining?”.
3. Nested Loop If the answer to the question is true, the
algorithm follows one path. If the answer
is false, the algorithm follows a different
While Loop path.
The While Loop can execute a set of Iteration refers to the process of doing
commands till the condition is true. the same task over and repeatedly, until
While Loops are also called conditional a certain task is complete, or a certain
loops. condition is met. The iteration can also
Once the condition is met then the loop be set to run for a specific number of
is finished. times. For example, think of a race in
which a car must go around a track five
times. The car will keep going around
For Loop the track repeatedly until it completes
For Loop is needed for iterating over a five laps. Once that is done, it will exit
sequence. A for loop executes for a the track.
specific number of times. Now let us see how we can combine all
Nested Loops the three building blocks of algorithms –
sequencing, selection, and iteration.
Any loop in program may contain
another loop inside it. When there is a In real life, complex algorithms can have
loop inside another loop, it is called as a hundreds, if not thousands, of steps in
nested loop. How it works is that first a sequence. However, often while
working on a sequence, you will notice
30 | P a g e
that certain activities in the sequence For example, in the last exercise, while
are repeated. We can reduce the number creating a rectangle, we had to turn right
of steps of the sequence by using a loop after drawing a line and we had to do so
along with certain conditions to check three times.
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:
31 | P a g e
32 | P a g e
33 | 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/).
34 | P a g e
Take a look at flowchart in Fig 1.0 understand how Arun uses concept of iteration while
distributing birthday sweets with the class.
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.
35 | P a g e
2.12 Quiz Time
36 | P a g e
Standard Questions
Applied Project
Create a rectangle of length 5 and height 3 using a loop (repeat block) in Minecraft.
By now you:
37 | P a g e
FUN WITH FUNCTIONS
38 | P a g e
3.3 Examples of Functions in Arcade
Example 1: Calling a function which has no parameters.
39 | P a g e
Example 2: Calling a function with a single parameter
40 | P a g e
Example 3: Calling a function to print statements.
41 | P a g e
3.4 Activity: Adding two integers
In Minecraft Editor, click on “Make a Function” button from “Functions” link in toolbox.
42 | P a g e
43 | P a g e
steps in a single action. Thus, every time
we include “Drink water” in our routine,
3.5 How to reduce redundancy
it will automatically cover the above 4
using Functions? steps.
To illustrate this, let us take a very basic
Similarly, the main idea behind using a
human habit of drinking water.
function in your code is to keep the code
If we look at the action of drinking water, DRY (Don’t Repeat Yourself). Cutting
it involves 4 main steps only: out repeated commands helps to
minimize errors, keeps code short, and
• Take a glass of water. saves programming time.
• Sip the water from the glass.
• Gulp the water down the throat.
• Put down the glass when we are 3.6 Advantages of using
no longer thirsty. Functions
Although the action “Drink water” Few of the advantages of using functions
constitutes of 4 steps, yet while are:
describing our day today life routine to
someone else, we use the phrase like Increases readability makes code
“Drink water”. This action of “Drink organized and easy to understand.
water” is easy for the other person to Reduces code length: redundant code
understand and covers up the above 4 is removed and replaced by functions.
44 | P a g e
Reusability: Code reusability increases. Similarly, if we want to calculate the
area of a rectangle, we need to know the
length and breadth of the rectangle.
3.7 What are different Here too, the formula for calculating the
Function Parameters? area of the rectangle always remains the
same.
So, in the above-mentioned scenarios, if
Consider a problem statement, where we
we consider the task of calculating the
are required to calculate the area of a
area of circle & square as functions
circle. To do so, we need to know the
respectively, then the formulae used to
radius of the circle whose area we are
calculate the area can be considered as
required to calculate.
the body of the function. However, to get
However, the formula for calculating the a concrete value from the functions, we
area of a circle always remains the same. need to provide the value of radius in
case of calculating the area of a circle &
the value of length & breadth to
calculate the area of the rectangle.
Thus, the variables accepted by a
function to perform the set of tasks
defined in its body are called function
parameters.
45 | P a g e
46 | P a g e
3.9 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:
47 | 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:
48 | P a g e
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.
49 | P a g e
50 | P a g e
51 | P a g e
52 | P a g e
53 | P a g e
54 | P a g e
55 | P a g e
56 | P a g e
3.11 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.
57 | P a g e
58 | P a g e
59 | P a g e
60 | P a g e
61 | P a g e
62 | P a g e
63 | 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/)
64 | P a g e
This “on player walk” block is an event
handler. Agent mode forward is the
3.12 What is an event?
action that occurs with this event.
An event is something that happens. In
the context of coding, events are a
generalization of all the things that the
program can respond to.
Some common examples of event
include:
1. Clicking on the button of a web
page
2. A web browser fully loading a web
page
3. Key press inside a desktop
application
65 | P a g e
3.14 Quiz Time
Option 1 True
Option 2 False
66 | P a g e
Standard Questions
if x > y:
return y
print(test1(2, 7, -1))
def sum(numbers):
total = 0
for x in number:
total += x
return total
print ( sum ( ( 1 , 2 , 3 , 4 , 5 ) ) )
67 | P a g e
Higher Order Thinking Skills (HOTS)
Applied Project
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.
2. Create a block code which computes product of (sum of two random numbers)
with the (difference of two random numbers) using functions.
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.
68 | P a g e
UNDERSTANDING ARRAYS & COLLECTIONS
69 | P a g e
Have a look at below optimized
algorithm.
Example 1: Is 36 a perfect square?
In the below algorithm, “n” is the input As you must have noticed, the number
number (36 in this case) of times we multiply, and compare is
reduced significantly in the above
Output is true if the number is a perfect
square, and false if it is not a perfect 1. Say number is n
square.
2. Start a loop from 1 to n/2
3. During iteration, for every integer
begin ‘i’, calculate x = i*i
4. Now with this ‘x’ there are 3
for num :=1, num <= n, increase num
by 1: possibilities:
a. If x == n then n is a perfect
if n is divisible by num, and n / num square, return true.
== num, then b. If x > n then x has crossed
the n, is not perfect square.
return true
Return false
done c. If above step a or b are not
true, then continue.
return false
end algorithm. This is how we can use
optimized algorithm to find the square of
Can you think of ways to improve the numbers.
algorithm?
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.
70 | P a g e
Step 4: From “Variables”, drag “set” into the “On start” block.
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.
71 | P a g e
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”.
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.
72 | 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).
73 | 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
74 | 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.
75 | 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!
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
76 | P a g e
data. However, there are following
limitations that we need to note while
4.5 What are Arrays?
using Arrays.
An Array is a collection of similar data
type variables. Arrays do not support Consider an Array with variables of
different data types in same collection. Integer Data Type stored in it.
For example, you can make an Array of This array can be declared in following
Integers as well as another Array of format:
Strings. However, you cannot make an
Array having Integer and Strings in arr = [10, 20, 30, 40, 50, 60];
same Collection. Using the above syntax, we can deduce
In real world, you can consider books in that an array named “arr” is declared
a library to be the example of arrays with data type as integer i.e this array
where all the shelves have a common can only hold integer values. We have
data type (read – book) in it. initialized this array with six values i.e
10, 20, 30, 40, 50, 60.
Arrays improve readability of code by
using a single variable for a large set of
Below is the diagram that displays how
Limitation of Arrays
data and indexes are structured in such
• You can only store variables an Array:
with same data types in an
Array
• The variables in an Array are
always ordered sequentially
with index starting with 0
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:
77 | P a g e
Let us now follow below step by step procedure to replicate this output on our screen:
78 | P a g e
79 | P a g e
80 | 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
81 | P a g e
4.6 Examples of arrays using Arcade
Example 1: Printing the first element of the array
82 | P a g e
Example 3: Adding an element in an array
83 | P a g e
there is a limitation on what can be
modified in a collection. As we have read
above, modifying a collection's elements
while iterating through that collection is
not allowed and throws an error in the
program. We cannot directly add or
remove elements while iterating through Adding Elements During Iteration
the collection that includes them.
To add elements while iterating a list, set
Below are certain points that we need to or map, keep the new elements in a
note about collections: temporary list, set, or map and add them
to the original after you finish iterating
• Collections that do not support
modification operations (such the collection.
as add, remove and clear) are
known as “unmodifiable”.
Collections that are not Removing Elements During Iteration
unmodifiable are modifiable.
To remove elements from a list, you can
• Collections which guarantee
create a new list, then insert the
that no change in the
elements you wish to keep. Or, add the
Collection object will be visible,
elements you wish to remove to a
are known as immutable.
different list and remove them after you
Collections that are not
finish iterating the collection.
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.
84 | P a g e
4.9 Quiz Time
Question 3 An array is
85 | 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
2. Write a program to create an array of prime numbers from 50 to 100.
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.
By now you:
86 | P a g e
HELLO WORLD WITH CODE
every year. Some of the most popular
5.1 What will you learn this programming languages are Python,
JavaScript, Java and C++. Later in this
chapter? chapter, we will look at some of the basic
syntax of Python.
At the end of this chapter, you will Low Level vs High Level Programming
understand the basics of a programming Language
language.
87 | P a g e
5.3 Activity – Sorting the list
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}
88 | P a g e
Step 1: For i = 0
Step 2: For i = 1
Step 3: For i = 2
89 | P a g e
Step 4: For i = 3
5.4 Getting used to syntax You will be surprised to know that some
of the world’s most famous websites like
Google, YouTube and Instagram use
Python is an easy to learn programming Python!
language that can be used to build a
variety of applications. Python is used in Now let us get started with some basic
web development, game development Python syntax.
and development of desktop-based
applications. Python is also widely used
for data science, machine learning and
artificial intelligence.
90 | P a g e
5.5 What are Variables and Let’s look at the syntax for these
Data types in operations.
programming? Defining a variable ‘Text’ and setting its
value.
91 | P a g e
• Modulus (Remainder) 4. Performing Division of Integers
and Floats
Now that we know what Integers and
Floats are, let us now understand the x = 1
syntax for performing different
Mathematical operations on them in our y = 2
Program: division = x / y
1. Performing Addition of Integers
and Floats
5. Performing Modulus of Integers
x = 1 and Floats
y = 2 x=1
sum = x + y y=2
2. Performing Subtraction of modulus = x % y
Integers and Floats
x = 1
Now that we are familiar with various
y = 2 arithmetic operations, in the next
subtraction = x - y exercise, we will get to understand more
on this topic.
3. Performing Multiplication of
Integers and Floats
x = 1
y = 2
multiplication = x * y
To understand these operations better, let us now perform the below activity. You need
to open MakeCode editor for this activity.
92 | P a g e
93 | P a g e
94 | P a g e
95 | P a g e
96 | P a g e
97 | 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 True
Option 2 False
98 | P a g e
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
99 | P a g e
Short Answer Questions
Applied Project
100 | 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
101 | P a g e