ClassVII Coding Project Booklet
ClassVII Coding Project Booklet
CODING CURRICULUM
GRADE VII
Volume 1.0
TABLE OF CONTENTS
Distributing Birthday Sweets............................................................................1
Arranging The Books ......................................................................................3
Algorithm For A Perfect Square.........................................................................5
Sorting The List .............................................................................................7
Variable Initialization In Programming ............................................................. 11
Drawing A Rectangle Using Minecraft .............................................................. 14
Better Way To Create A Square ....................................................................... 20
Fun Activity: Chase the apple ......................................................................... 24
Adding two integers ...................................................................................... 34
Finding the square of a number ...................................................................... 37
Can a function return value ........................................................................... 38
Calculating Area Of A Circle ........................................................................... 46
Create An Array And Calculate Its Length......................................................... 55
Building A Zoo............................................................................................. 59
Examples of Simple functions in Arcade ........................................................... 67
Examples of arrays in Arcade ......................................................................... 71
Building a calculator .................................................................................... 73
References .................................................................................................. 79
I
Distributing Birthday Sweets
Problem Statement:
Consider there is a birthday of one of the students in your class today, named Arun.
As a normal birthday ritual, he is planning to distribute the birthday sweets amongst
the students. Can you draw a flowchart of the activities that he performs while
distributing the birthday sweets within the class?
Learning Outcomes:
At the end of this exercise, you will learn:
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.
1|Page
Distributing Birthday Sweets
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.
2|Page
Arranging The Books
• Learn the concept of sorting how sorting is applied in the activities that we
perform of daily basis.
Solution:
In this activity, you will learn about the concept of “Sorting” in programming.
For the given problem statement, if you want to arrange these books, you can do it in
many ways.
For Sorting, we need to know how to compare two items. So, we will ask questions like:
Which book is taller/shorter?
3|Page
Arranging The Books
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.
4|Page
Algorithm For A Perfect Square
Learning Outcomes:
At the end of this exercise, you will learn:
Solution:
In this activity, we will learn to write an algorithm for finding if a number is a perfect
square.
To start with let us take a look at following questions:
In the below algorithm, “n” is the input number (36 in this case)
Output is true if the number is a perfect square, and false if it is not a perfect square.
5|Page
Algorithm For A Perfect Square
begin
done
return false
Can you think of end ways to improve the
algorithm?
1. Say number is n
2. Start a loop from 1 to n/2
3. During iteration, for every integer ‘i’, calculate x = i*i
4. Now with this ‘x’ there are 3 possibilities:
a. If x == n then n is a perfect square, return true.
b. If x > n then x has crossed the n, is not perfect
square. Return false
c. If above step a or b are not true, then continue.
As you must have noticed, the number of times we multiply, and compare is reduced
significantly in the above algorithm. This is how we can use optimized algorithm to find
the square of numbers.
6|Page
Sorting The List
Solution:
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.
7|Page
Sorting The List
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.
Let us now sort the below array in ascending order using selection sort algorithm:
Array = {3, 2, 11, 7}
Step 1: For i = 0
8|Page
Sorting The List
Step 2: For i = 1
Step 3: For i = 2
Step 4: For i = 3
9|Page
Sorting The List
The final state of array after loop is terminated looks like below:
10 | P a g e
Variable Initialization In
Programming
Learning Outcomes:
At the end of this exercise, you will learn:
• Learn to create variables that represent different types of data and manipulate
their values.
• Learn how to create clearly named variables that represent different data types
and perform operations on their values.
11 | P a g e
Variable Initialization In
Programming
12 | P a g e
Variable Initialization In
Programming
We have now completed this exercise and learnt how can create and initialize variables
in programming
13 | P a g e
DRAWING A RECTANGLE USING MINECRAFT
This activity will help you understand about sequencing with the help of Minecraft.
What would be the steps to draw a rectangle of length 5 cm and height 3 cm on your
screen?
Problem Statement: Suppose that you are sitting in a mathematical class and the
teacher asks you to draw a rectangle. You know how to draw in using pen and paper.
Can you think how you can draw a rectangle of length 5 cm and height 3 cm on screen?
Learning Outcomes:
At the end of this exercise, you will learn:
• Learn how the sequence of the code affects how the code runs.
• Learn how to write algorithm for drawing various geometrical shapes using
sequencing.
Solution: 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
Drawing A Rectangle Using
Minecraft
15 | P a g e
Drawing A Rectangle Using
Minecraft
16 | P a g e
Drawing A Rectangle Using
Minecraft
17 | P a g e
Drawing A Rectangle Using
Minecraft
18 | P a g e
Drawing A Rectangle Using
Minecraft
If you complete the steps above, you should be able to create a rectangle.
19 | P a g e
Better Way To Create A Square
Problem Statement: Suppose you are told to draw a square of side 5cm. You can either
do it using pen and paper or you can draw it on screen using algorithm for programming.
Now that you have learnt the concept of sequencing with loops and conditionals, can
you think of steps to draw a square of side 5 cm on your screen?
Learning Outcomes:
• Learn to use loops and conditionals to allow the program to perform repeated
tasks.
• Learn the importance of using “do while” with conditional loops.
• Learn to use conditional loops to complete challenges.
Solution: 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
20 | P a g e
Better Way To Create A Square
21 | P a g e
Better Way To Create A Square
22 | P a g e
Better Way To Create A Square
23 | P a g e
Fun Activity: Chase the apple
24 | P a g e
Fun Activity: Chase the apple
25 | P a g e
Fun Activity: Chase the apple
26 | P a g e
Fun Activity: Chase the apple
27 | P a g e
Fun Activity: Chase the apple
28 | P a g e
Fun Activity: Chase the apple
29 | P a g e
Fun Activity: Chase the apple
30 | P a g e
Fun Activity: Chase the apple
31 | P a g e
Fun Activity: Chase the apple
32 | P a g e
Fun Activity: Chase the apple
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
33 | P a g e
Adding two integers
Learning Outcomes:
At the end of this exercise, you will learn:
Solution: In Minecraft Editor, click on “Make a Function” button from “Functions” link
in toolbox.
34 | P a g e
Adding two integers
35 | P a g e
Adding two integers
36 | P a g e
Finding the square of a number
Learning Outcomes:
At the end of this exercise, you will learn:
37 | P a g e
Can a function return value
38 | P a g e
Can a function return value
Problem Statement: You have learnt about finding squares and cubes of numbers in
Mathematics. You can find these squares and cubes through programs too. Consider
you have to create a function which returns the value of square and cube of any given
number and returns the result as a return value from the function. Can you write a
block code for this function in Minecraft?
Learning Outcomes:
At the end of this exercise, you will learn:
39 | P a g e
Can a function return value
40 | P a g e
Can a function return value
41 | P a g e
Can a function return value
42 | P a g e
Can a function return value
43 | P a g e
Can a function return value
44 | P a g e
Can a function return value
45 | P a g e
Calculating Area Of A Circle
Learning Outcomes:
At the end of this exercise, you will learn:
46 | P a g e
Calculating Area Of A Circle
47 | P a g e
Calculating Area Of A Circle
48 | P a g e
Calculating Area Of A Circle
49 | P a g e
Calculating Area Of A Circle
50 | P a g e
Calculating Area Of A Circle
51 | P a g e
Calculating Area Of A Circle
52 | P a g e
Calculating Area Of A Circle
53 | P a g e
Calculating Area Of A Circle
54 | P a g e
Create An Array And Calculate Its Length
55 | P a g e
Create An Array And Calculate Its Length
56 | P a g e
Create An Array And Calculate Its Length
57 | P a g e
Create An Array And Calculate Its Length
58 | P a g e
Building A Zoo
BUILDING A ZOO
Chapter: Understanding Arrays and Collections
Problem Statement: You must have played many games where you saw a zoo full of
different animals and you must have performed different actions for adding deleting
these animals and saving them from each other to proceed in the game. In this activity,
you will implement the concept of arrays that you learnt about programming. To
complete this activity, create an array in Minecraft and fill it up with animals of your
choice.
Learning Outcomes:
At the end of this exercise, you will learn:
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.
59 | P a g e
Building A Zoo
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.
60 | P a g e
Building A Zoo
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.
61 | P a g e
Building A Zoo
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 is able to place fences along this path.
Step 14: From “PLAYER”, drag an “on chat command” block to the Workspace.
62 | P a g e
Building A Zoo
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
63 | P a g e
Building A Zoo
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.
64 | P a g e
Building A Zoo
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!
65 | P a g e
Building A Zoo
66 | P a g e
Examples of Simple functions in Arcade
67 | P a g e
Examples of Simple functions in Arcade
68 | P a g e
Examples of Simple functions in Arcade
69 | P a g e
Examples of Simple functions in Arcade
70 | P a g e
Examples of arrays in Arcade
71 | P a g e
Examples of arrays in Arcade
72 | P a g e
Building a calculator
BUILDING A CALCULATOR
Chapter: Hello World with code
Problem Statement: In this activity, you will build a calculator in MakeCode
To understand these operations better, let us now perform the below activity. You need
to open MakeCode editor for this activity.
73 | P a g e
Building a calculator
74 | P a g e
Building a calculator
75 | P a g e
Building a calculator
76 | P a g e
Building a calculator
77 | P a g e
Building a calculator
78 | P a g e
References
REFERENCES
1. Microsoft MakeCode Arcade. 2021. Microsoft MakeCode Arcade. [ONLINE]
Available at: https://arcade.makecode.com. [Accessed 23 February 2021]
2. Microsoft MakeCode for Minecraft. 2021. Microsoft MakeCode for Minecraft.
[ONLINE] Available at: https://minecraft.makecode.com. [Accessed 23 February
2021]
3. Microsoft MakeCode. 2021. Activity: We Built a Zoo. [ONLINE] Available at:
https://minecraft.makecode.com/courses/csintro/arrays/activity-1. [Accessed
23 February 2021]
4. Association for computing machinery (acm). 2016. CSPathsala. [Online]. [16
March 2021]. Available from: https://cspathshala.org
79 | P a g e