67% found this document useful (3 votes)
2K views109 pages

ClassVII Coding Student Handbook

This document is the student handbook for coding in grade 7. It acknowledges contributions from government officials and organizations that helped develop the handbook. The purpose is to introduce coding skills to students starting in 6th grade. It will cover topics like variables, sequencing, functions, arrays and collections. Coding helps build problem solving skills. Resources like Minecraft Education and Microsoft MakeCode are recommended for learning coding in a fun way. The handbook contains chapters that use examples and activities to explain coding concepts and practices step-by-step.

Uploaded by

manan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
2K views109 pages

ClassVII Coding Student Handbook

This document is the student handbook for coding in grade 7. It acknowledges contributions from government officials and organizations that helped develop the handbook. The purpose is to introduce coding skills to students starting in 6th grade. It will cover topics like variables, sequencing, functions, arrays and collections. Coding helps build problem solving skills. Resources like Minecraft Education and Microsoft MakeCode are recommended for learning coding in a fun way. The handbook contains chapters that use examples and activities to explain coding concepts and practices step-by-step.

Uploaded by

manan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 109

INTRODUCTION

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

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

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 What will you learn in this chapter? .......................................................2
1.2 What is Variable Initialization? ..............................................................2
1.3 Data Types in programming ..................................................................6
1.4 How do we validate user input in programming? .......................................6
1.5 Math Operations in Programming...........................................................7
1.6 Quiz Time ..........................................................................................8
1.7 What have you leant in this chapter? .................................................... 10
Sequencing with Block Coding........................................................................ 11
2.1 What will you learn in this Chapter? ..................................................... 11
2.2 Recap of Loops ................................................................................. 11
2.3 What is Sequencing? ......................................................................... 11
2.4 Examples of Sequence, Selection and Iteration ....................................... 12
2.5 What is a Bug? ................................................................................. 14
2.6 Activity Drawing Rectangle.................................................................. 14
2.7 Fun Activity: Chase the Apple.............................................................. 20
2.8 Types of Loops.................................................................................. 30
2.9 Apply Loops and Conditionals with sequencing....................................... 30
2.10 Is there a better way to apply sequencing? .......................................... 31
2.11 Activity: Distributing Birthday Sweets ................................................ 34
2.12 Quiz Time ..................................................................................... 36
2.13 What have you learnt in this chapter? ................................................ 37
Fun with Functions ...................................................................................... 38
3.1 What will you learn in this chapter? ..................................................... 38
3.2 What exactly are Functions? ............................................................... 38
3.3 Examples of Functions in Arcade ......................................................... 39
3.4 Activity: Adding two integers ............................................................... 42

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.

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

1.2 What is Variable a=5


Initialization? b = “Hello”
To use variables in programming, we
need to create the variables and assign
them a reference in computer memory.
Once we create a variable, we also need Let us now do a practice exercise in
Minecraft: Education Edition to
to assign it a value before it is used at
all. This process of assigning a value to understand how variable initialization
works in programming. You setup
variable is called Initialization.
Minecraft education edition from
A variable that is not initialized ever has https://education.minecraft.net/get-
an undefined value. Such a variable started.
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

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

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

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

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

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

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;

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;

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.

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

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.


2. Write a program to count the occurrence of the letter “a” in string “We are a
family”.

9|Page
Applied Project

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

1.7 What have you leant 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.

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.

2.3 What is Sequencing?


An algorithm is a detailed step-by-step
process that needs to be followed in

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

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
Now let us understand the concept of
we learn in the future will build on this
Selection using an example.
concept.
Look at below pseudocode to check if age
entered by the user is of a senior citizen
or not. Consider that person is

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.

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 As you can see in the flow chart the flow
is less than 60, the program enters else of the program will repeat or iterate for
block. 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
workflow. This is how iteration works in
Moving forward, let us have a look at programming. It will repeat the block of
example of Iteration. code for multiple times till the specified
condition is achieved.
In programming, loops follow the
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

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.

2.6 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/

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

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

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.

2.9 Apply Loops and


Conditionals with
2.8 Types of Loops sequencing

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

2.10 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:

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

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

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

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

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

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

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

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

36 | P a g e
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.


2. Draw a flowchart to explain the iterative process that Arun followed while
distributing birthday sweets.

Applied Project

Create a rectangle of length 5 and height 3 using a loop (repeat block) in Minecraft.

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

37 | P a g e
FUN WITH FUNCTIONS

A function is a block of code made up of


a set of steps that results in a single
3.1 What will you learn in this
specific action. The programmer will give
chapter? this action a simple name. Giving a
At the end of this chapter, you will simple name to a function, increases the
understand the use of functions in chances that the set of steps can easily
programming. You will know: talked about and reused again and again
in the program.
• 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.2 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.

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.

3.8 Activity – Finding the square of a number

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:

Which book is taller/shorter?

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:

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.

3.10 Activity: Calculating area of a circle

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.

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
program 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.
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 Let us see how we can implement the
print them. above example via Minecraft

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

3.13 What are Event Handlers?


An event handler is a piece of code
associated with an event in the code. An
event handler gets executed, when that
event occurs. For example, in MakeCode
platform if you want a player to move
forward when the user clicks on the
forward icon you would create a code
block like below.

65 | P a g e
3.14 Quiz Time

Objective Type Questions

Question 1 Function in a program decreases readability


Option 1 True
Option 2 False

Question 2 Function in a program increases code reusability


Option 1 True
Option 2 False

Question 3 Functions in programming help in reducing code redundancy

Option 1 True
Option 2 False

Question 4 A function can return a value


Option 1 True
Option 2 False

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

66 | P a g e
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:

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

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

67 | P a g e
Higher Order Thinking Skills (HOTS)

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


2. Write a function to do sort the elements [34,12,89,56,98,101] from biggest to
smallest.
3. Write a function to find the highest number in the array of [1, 87, 09, 18, 11]
4. Write a function to find the modulus of 3 and 6.

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.
2. Create a block code which computes product of (sum of two random numbers)
with the (difference of two random numbers) using functions.

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

68 | P a g e
UNDERSTANDING ARRAYS & COLLECTIONS

• Collections allow programmers to


4.1 What will you learn in this group multiple items into a
common set
chapter?
• Grouping of items makes it easier
to identify and perform different
operations on them like retrieving
This chapter will teach you how we can
and modifying data
work with large set of data in
• It increases the performance of
programming. What are Arrays and its
the program
practical implementation in computers.
• It increases productivity and
This chapter will also give you an
reduces operational time.
overview of collections. We will work on
some fun exercises to get better
understanding of these concepts 4.3 Activity – Algorithm for a
perfect square
4.2 What are Collections?
In this activity, we will learn to write an
A collection is nothing but a container algorithm for finding if a number is a
that groups multiple items into a single perfect square.
object. Collections are used to store To start with let us take a look at
data. We can also retrieve and following questions:
manipulate data that is stored in the
Collections. • How quickly can you determine
whether a number is a perfect
square?
In real world, you can consider a • And, if a number is a perfect
collection of cards, a telephone directory square, how can you find out its
or a mailbox to be an example of square root?
Collections. • Can you write the steps for
finding the same for any given
Advantages of using Collection large number?
• Let us try with a few examples
and identify the repeatable steps
in the process.

69 | P a g e
Have a look at below optimized
algorithm.
Example 1: Is 36 a perfect square?

We can use the below algorithm to solve


this problem:

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?

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

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

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

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

4.7 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.8 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

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.

Let us now understand the


modifications that we can do on
collections.

84 | P a g e
4.9 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

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]

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

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

85 | P a g e
Standard Questions

1. What are collections?


2. What are different types of collections?
3. How can we iterate over collections?
4. What are the different types of modifications that we can perform on
collections?
5. What is an Array Index?
6. Do collections allow backward traversing of data? Support your answer with a
proper explanation.
7. 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
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.

4.10 What have you learnt in this chapter?

By now you:

• Should know what arrays are and their practical implementations


• Should know about collections

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.

Programming languages are of two


5.2 What is a Programming types, high-level languages and low-level
Language? languages. Both high-level and low-level
languages have their own applications,
so it is important to understand the
A computer program is a set of difference between the two types of
instructions that is given to a computer languages.
to execute. A programming language is a
A low-level programming language is one
tool we use to write instructions for
that is made to be easily understood by
computers to follow.
the computer. They include machine
We need a programming language since code and assembly language, both of
computers cannot understand the which instruct computer hardware
languages we speak. Computers can components to carry out instructions
only understand binary strings of 1s and directly. However, low-level
0s. programming languages are difficult to
learn and time-consuming to code.
The very earliest computers were
programmed by changing ones and A high-level programming language is
zeros manually, alternating the circuit made to help human programmers
and the wiring. All modern programming communicate easily to the computer.
languages, however, are made up of a Good examples of high-level
series of syntax and symbols that act as programming languages include C,
a bridge that allows humans to translate Java, Python. These languages are
their thoughts into instructions that usually compiled or converted into low-
computers can understand. level programming languages so that
they can be executed directly. The
Over the years, thousands of
person who invented the concept of a
programming languages have been
compiler was Grace Hopper, sometimes
created, and more are being created
called "Amazing Grace".

87 | P a g e
5.3 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.

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}

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

The loop gets terminated as “I” becomes 2.


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

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.

Text = “This is a string variable.”


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

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

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

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

5.7 Quiz Time


Objective Type Questions

Question 1 Low level languages are user friendly

Option 1 True
Option 2 False

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


Option 1 string
Option 2 integer
Option 3 float
Option 4 All the above

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

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”

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

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

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
Option 4 Medium Language

99 | P a g e
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 are variables 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.


2. Write an algorithm to sort the below list in descending order using Selection Sort
Technique:
[10, 21, 45, 67, 12]

Applied Project

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

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

100 | 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

101 | P a g e

You might also like