Early Coding For Kids e
Early Coding For Kids e
Lead Author
David Ogunshola
Levels 1 - 5
www.earlycodingbook.com
About the Author
David Ogunshola is widely recognized for his work as an innovation catalyst. He has a
Bachelor's Degree in Computer Science, M.A. in Organizational Leadership and an M.Ed in
STEM Education from the American College of Education. He holds the National Certificate for
STEM Teaching (NCST) a prestigious certification offered by the National Institute for STEM
Education (NISE) in the USA.
David has worked for more than 15 years as a Software Developer, Tech Founder and
Educator. He is the co-founder of Brainy Hive Schools, a future-driven K-12 school in Nigeria,
founder of EarlyFounders Labs - a tech and startup school for children and Founder of
Daveshoope Inc, a Software Development & AI Consulting company.
His interest in high-quality disruptive education and desire to lower the age of innovation in
Africa led him into education and pedagogy. He has had successful results teaching children to
code and launch startups as teenagers. The lack of age-appropriate educational resources for
his teaching needs inspired the journey into the creation of these and many more books and
learning pathways. The books have undergone multiple iterations and every lesson in each book
has been tested in a real classroom.
These books are aimed at teaching children and young learners not just to be consumers
of technology but to be creators and inventors. Early Coding (Levels 1 to 5) will help
children to understand how the computer thinks and how to create their own programs,
games, animations and anything they can imagine using a computer programming
language. It has been designed in a way that it can be used in schools or at home for
personal learning. There is no age limit on who can use the book, even children from age
five can understand the concepts.
Many people assume that coding is too difficult for children to learn, but we have seen
children from age five learn how to code.
Your child/student would not only be learning to code. Beyond programming computers,
here are other skills that children learn in the process that they can transfer to other areas
of their lives:
How to recognize patterns and follow a sequence of actions to accomplish tasks
Analytical thinking and problem-solving - the ability to look at big problems, study them
and break them down into smaller parts to find solutions
Concentration, discipline and perseverance to finish tasks they start
Creativity and imagination: the ability to ask questions, experiment, make mistakes and
learn from their exploration
Digital Citizenship: the responsible use of technology, especially in a world that is
becoming increasingly internet-driven
And much more
Our goal is not just to teach coding but to prepare children to be creative thinkers and
problem solvers.
Not all the lessons and activities require a screen, but many of the applications and
experiments will be made using a programming language called Scratch in the earlier
levels and Python in advanced levels. Scratch uses commands in the form of blocks
dragged together to instruct the computer. Scratch and Python are free and work without
the internet. Children would require access to a computer to make the best use of these
books.
David Ogunshola
[email protected]
Sample lessons from Level One - Five
Computer Programming, Digital Citizenship and
Analytical Thinking for Children
David Ogunshola
table of contents
Programming Coding
Languages
David Ogunshola
www.earlycodingbook.com
Computer programs
How computers know what to do
Computers do not think and cannot figure things out themselves the way human beings
can, they only follow instruction that has been given to them by human beings.
Computers have a brain called 'memory' where all programs are stored. When a computer follows the
instructions in a program given to it, we say the computer is running the program.
Computers can only run programs that have been stored in their memory. The process of adding a
program to the memory of a computer is called installation.
Event End
Something or someone Program
tells the program when The computer begins to When the instructions
to start. This could be a follow the list of are over, the computer
button, a voice instructions provided in does something to let
command or instruction the program. you know it has
from another program. completed.
8 David Ogunshola
www.earlycodingbook.com
Your first computer program
The robot needs to get to the cookie. We would write a program to help the robot reach the box
with the cookie.
Program
1. Move Right
2. Move Right
3. Move Right
Using the following instructions, help the robot get to each cookie:
MOVE RIGHT MOVE LEFT MOVE UP MOVE DOWN
Program
1.
2.
3.
4.
5.
Program
1.
2.
3.
4.
Computer Games, Mobile phone apps, Traffic Light Controllers, ATM Machines, and Elevators are all
examples of computer programs.
9 David Ogunshola
www.earlycodingbook.com
algorithms
How computer programs know what to do
13 David Ogunshola
www.earlycodingbook.com
sequence
Making things follow the right order
All instructions given to a computer contain a list of steps, but these steps need to
be performed in a particular order for the task to be correctly done.
A sequence is the order the steps Even when the instructions are correct, there would
be a bug if the sequence is wrong. For computers to
needed to complete a task must complete tasks, we need to write our codes or
follow. algorithms in the right sequence.
1 3 4 2 5 1 2 3 4 5
Add teabag
Add Milk
Boil water
17 David Ogunshola
www.earlycodingbook.com
pathway ninjas
Following Algorithms You will need crayons
To become a good programmer, you need to understand how computers follow instructions,
In Pathway Ninjas, you pretend to be a robot. You have been given an algorithm to follow.
Each algorithm has instructions and a pathway map to follow. Follow each step in the algorithm and do exactly what it says
on the map.
Pathway 1
Follow each step on the map
1. Go right one step
2. Go up two steps and colour the box orange
3. Go up two steps
4. Go right one step and colour the box blue
5. Go right two steps and colour the box green
6. Go down four steps and colour the box
purple
7. Go left 2 steps and colour the box yellow
Map
(Start where the arrow is)
If you do not have crayons, just use your pen to color the box.
You should have something like this.
Pathway 2
Follow each step on the map
Map
(Start where the arrow is)
22 David Ogunshola
www.earlycodingbook.com
Pathway Ninjas without words
Now let us convert our words to codes. These would be our codes
Pathway 6
1.
2. Go Right
3.
4.
5.
Map
(Start where the arrow is)
Pathway 7
1.
2. Go Right
3.
4.
5.
Map
(Start where the arrow is)
24 David Ogunshola
www.earlycodingbook.com
Binary Coding
Computers and all electronic devices do not read words the way human beings do. They only recognize a
special language where there are only two alphabets, this language is called binary language. When
programmers write code in any programming language, the code is eventually converted to binary so
that the computer can understand.
To learn binary, we would convert all the letters in the English alphabet to binary. Each alphabet has
eight binary characters consisting of 1’s and 0’s.
Each character is called a Bit.
B 01000010 O 01001111
C 01000011 P 01010000
D 01000100 Q 01010001
E 01000101 R 01010010
F 01000110 S 01010011
G 01000111 T 01010100
H 01001000 U 01010101
I 01001001 V 01010110
J 01001010 W 01010111
K 01001011 X 01011000
L 01001100 Y 01011001
M 01001101 Z 01011010
26 David Ogunshola
www.earlycodingbook.com
binary decryption
We can use binary chart to convert binary code back to normal text.
This is called Decryption.
Decryption is the process of converting information from code back to what people can read.
To do this, we would use the binary chart again to see what alphabet the code represents.
01000010 B 01000111
01010101 U 01010010
01000111 G 01000101
01000101
01001100
01001110
01000001 Hint: this is a color
01000111 01001101
01001111 01001001
01010011 01001100
Hint: this is a city in Africa
01001011
activity
Choose a word. Encrypt it into binary and exchange your book with a friend to see if they can
decrypt your word. Do not tell them what word you encrypted allow them to figure it out.
28 David Ogunshola
www.earlycodingbook.com
Manage sounds Full screen
Change costume Start your program Stop your program
www.earlycodingbook.com
Sprite
David Ogunshola
Coding area
Drag your blocks of
35
code out here.
Stage
Show sprite
Hide sprite
Choose backdrop
Change size of
sprite
Code block
Rename sprite
categories Choose sprite
How to get Scratch
You can use Scratch on a computer or on some mobile devices. It can work on Windows, Apple
and Chrome laptops, or on special Android devices. This allows you to work in Scratch without
having an internet connection.
You can also use Scratch on the internet using any browser without installing the application on
your device.
Starting Scratch
Once you have installed Scratch on your device, you can
start it by clicking on the Scratch icon.
Before you begin using Scratch, there are four important things you need to know:
Blocks Backdrops
Blocks are command used to tell a These are images that determine the
sprite what to do. When you combine scene on the stage. You can add
multiple blocks together, it is called backdrops to your stage to make it look
a script. different.
36 David Ogunshola
www.earlycodingbook.com
ScratCh blocks
All the commands in Scratch are arranged into categories. In each section, you will find blocks
that do similar things. The major block categories in Scratch are explained below:
37 David Ogunshola
www.earlycodingbook.com
Scratch Project
What to do
Open a new Scratch project and
delete the cat sprite
Challenge:
Can you make the sprite move faster
towards the mouse?
What would you change to make that
happen?
What other block can you add into the
code to add more fun to the project
David Ogunshola
41 www.earlycodingbook.com
Challenge yourself
With the little you now know about Scratch, here are ideas of things you could try to
create until you get a copy of Level Two of this book.
You can also make it more fun by making the sprite change they way it
looks when it says different things
44 David Ogunshola
www.earlycodingbook.com
Computer Programming, Digital Citizenship and
Analytical Thinking for Children
David Ogunshola
table of contents
Patterns
Noticing when things repeat
themselves
Directions Coordinates
Which way should Understanding how
things go things move
Sounds Projects
Giving sound Push your imagination and
effects to programs develop your skills
Computer programming is about solving problems. Almost every computer program was created in an
attempt to solve a problem, and to be a good programmer, you must understand the process of solving
problems.
Computational Thinking is the process of breaking down a problem or task into simple steps
that a computer is able to understand.
People find it difficult to add, subtract, multiply A calculator program that people can install on their
and divide large numbers very fast. phones to help them with maths
People need to go to places, but they don't know A map program that can direct people anywhere from
how to find their way there. their phones, like Google Maps
People don't wake up early and they forget their A program that rings an alarm at a particuler time to
meetings and appointments? wake people up or remind them of appointments
This is why every instruction given to the computer in a program or algorithm needs to be very clear,
simple and detailed so that it can be carried out without confusing the computer. Once the computer or
program is not sure of what to do, you will have a bug.
4 David Ogunshola
www.earlycodingbook.com
The process of solving problems
Whenever you have a task or big problem you want to solve or an idea for a computer program to
create you need to follow these four steps. They will help you to understand the problem works, and
with that, you can create a solution to it. In the end, you will have a list of steps that could be written
into a computer program.
If you follow these steps, you can always solve any problem, no matter how big and complex it looks.
Problem
Program a robot to "feed the chickens"
The task may look big and complex, and if you just tell a robot, “feed the chickens” the robot could
get confused, especially if it is the first time.
There are many smaller questions that the robot needs to know before it can feed the chickens. For
example: where are the chickens? what do they eat? where is the food?
5 David Ogunshola
www.earlycodingbook.com
Events
What makes other things happen?
When we are creating programs, we use events to tell the computer when to start doing something,
when to change what it is doing or when to stop doing something.
Event Action
Event Action
10 David Ogunshola
www.earlycodingbook.com
Events in scratch
In Scratch and many other block programming languages, all events start with the word WHEN.
Every time you see a block that begins with the "WHEN", it can be used as an event. Every command or
script you attach to the event block will happen when that event is run.
The Event category contains the different events you can use to
start your program in Scratch. Event blocks are orange in color.
Scratch Events
Some of the popular events you will be using very often.
Clicking on the arrow inside the button allows you to choose which key
or letter on the keyboard you want to make your event.
Every command you put under this event will run when that key is
pressed.
11 David Ogunshola
www.earlycodingbook.com
loops
Making things happen again and again
A loop is a piece of code that makes an action to repeat itself over and over again.
Loops become useful when you have observed a pattern or you want to create a solution to a problem
that involves a pattern.
Remember the boy trying to cross the pathway with obstacles? If you are to create a program that
helps him cross the pathway, what will your code look like?
walk walk jump walk walk jump walk walk jump walk walk jump walk walk jump
1 2 3 4 5
Notice the pattern in the movement of the boy. He walks twice and then jumps. Because of this
pattern, he is repeating the same thing over and over again.
This is where a loop becomes useful. Instead of writing many lines of code to carry out each step,
you can use a loop to make the code repeat itself many times; in this example, the code will repeat
itself five times.
The Days of the Week The Hours in a Day The Months in a year
The week starts on Sunday, ends The day operates in a cycle. January to December makes a
on Saturday and begins again. Every day has two 12-hour loops. full year, but when the year ends,
This process continues forever. The day begins at 12 midnight, it starts again. That is also a
The week runs in a loop. runs till 12 noon, and then goes to loop
12 midnight again.
16 David Ogunshola
www.earlycodingbook.com
Changing sprites with code
The Looks section of your code contains blocks and commands that can be used to change the
way your sprite looks when the program is running. A few important Look blocks you should get
familiar with are:
The next costume block makes the sprite change to the next costume
on the queue in the order they are arranged.
If a sprite has five costumes, each time this block runs, it changes to
the next costume, and after the fifth costume, it goes back to the
first costume again.
The change size block makes the sprite become bigger or smaller
each time you run it. Using a positive number like 10 makes the
sprite bigger while using a negative number like -5 makes the sprite
become smaller.
The set size block returns the sprite back to its original size
when you use 100%. You can also use it to make a sprite bigger
and smaller in proportion to its original size.
24 David Ogunshola
www.earlycodingbook.com
Representing Coordinates x-axis
y-axis
writing them together like this (x,y)
Coordinates are written as a pair of
numbers in parenthesis separated by a
comma like this (32,75). The first number
represents x while the second number
represents y.
x = -3, y= 0
coordinate = (-3,0) x = 1, y= 3
coordinate = (1,3)
B
Pixel Coordinate
A
B
E C
D
D
F E
C
F
29 David Ogunshola
www.earlycodingbook.com
Moving Sprites Up and Down
In Scratch, the stage is 480 steps wide and 360 steps high.
This means that the y-axis is 480 and the x-axis is 360.
The middle point of the screen is usually represented by (0,0), meaning x=0 and y=0.
This also means that half of each is axis is positive while the other half is negative
180
360 steps along the y-axis
-240 240
0
-180
This means that when the y coodrinate of a sprite is on -240, it is on the extreme left of the
screen and when its x coordinate is on 180, it is at the extreme top of the screen.
To move a sprite on all directions on your screen, you will need the change x and change y blocks.
Y
+Y
X
-X +X
X
To move Up, change y by a positive number like 10
To move Down, change y by a negative number like -10
To move Right, change x by a positive number like 5
To move Left, change x by a negative number like -5
-Y
31 David Ogunshola
www.earlycodingbook.com
coding with sound
Using Voice, Music and Sound Effects in Scratch
Sound makes your programs or animations come alive and become more fun to interact with.
Without sound effects, video games will be boring, but you can use sounds to make whatever you
create enjoyable for the users.
When creating a game, you can add a sound whenever the player hits a coin, scores a goal or loses a
life. You can also play a sad sound when the player loses the game or a cheering sound when the
game is won.
Upload sound from your computer: you can import any sound, music or audio
from your computer or from any device into scratch.
Record your voice: you can talk, and scratch will record everything you say
and use it in your program.
35 David Ogunshola
www.earlycodingbook.com
Project: fruit catcher game
In this project, you will create a game where
fruits fall randomly from the sky, and a player
controls a bowl with which they can catch
fruits and earn points, but if the fruit falls to
the ground, they lose.
First, Decompose it
Break down the game into small tasks,
then try to solve them one by one.
Tasks:
1. Create the environment Start a new project
2. Choose your sprites 1
If you had any project you were working on earlier,
3. Make the fruits fall from the sky you will need to save it and start a new project
4. Make the player move the plate that has no code.
5. Determine when the fruit is caught or Remember to delete the cat sprite that comes
when it falls to the ground with every new project.
6. Add a score
7. Add sound effects Create the environment
2
The environment is determined by the
backdrop. So select a backdrop to
make your stage look like a good place
3 Choose your sprites to play the game.
Add the Apple sprite and the Bowl
sprite to the stage. Add a backdrop called "Blue Sky". You
can add backdrops by clicking this.
You might need to change their sizes:
make the size of the apple to be 75 and
the bowl to be 150.
4 Make the fruit fall from the sky 5 Add a sprite to be the
ground
Using a forever loop, you can Add the Line sprite and move
make the sprite fall from top to it to the bottom of the
bottom. But there is a problem. stage. That way, when the
The fruit stops once it gets to apple touches the line, we
the bottom of the stage. know it is on the ground.
We need to find a way to let the You will need a sensing
fruit know that it has reached condition to know when the
the bottom and then start apple is touching the ground.
falling from the top again.
39 David Ogunshola
www.earlycodingbook.com
Create your own animated stories
Under the Sea
Story:
Nemo and his friend starfish are
swimming randomly in the sea. There is a
shark who is also swimming randomly.
When the shark hits or runs into any of
them, he eats them up and they
disappear.
Scrambled
Blocks
These are some of the
blocks you will need, but
they are scrambled. Use
these blocks to create the
project described in the
story. Feel free to add
your own blocks too.
Scrambled
Blocks
These are some of the
blocks you will use. Use
them, and any others you
need to create the story in
Scratch.
41 David Ogunshola
www.earlycodingbook.com
Digital Citizenship
Your Digital Footprint is a record of everything you do online including the websites
you visit and things you share.
Have you ever walked on the wet floor without shoes on? You leave a
footprint behind that makes it possible to know that you have been there.
Even when you wear shoes, the sand leaves marks of your footprints.
Every time you go online, search the internet, visit a website, chat with a
friend, watch a video or play a game online, you leave a trail. They are
called digital footprints.
It is possible for someone to find out a lot about you, the things you like,
the things you say and even the things you are learning just by observing
your digital footprints. The more time you spend on the internet, the more
footprints you leave behind, and your digital footprints are permanent, it
is very difficult to erase them.
46 David Ogunshola
www.earlycodingbook.com
Felix & Joe's Digital Footprints
These are the things they both share on the internet
My name is Felix
Ubong, I am 13 Hi there, my name
years old and I live is Joseph, but you
with my parents on can call me Joe.
23 Utuk Street,
Uyo in Nigeria.
I love to dance,
swim and play the
I have an iPad and guitar.
I love to play candy
crush. My email
address is
[email protected].
If someone wants to steal from both of them, whose house can they find?
Who do you think has a safer and more responsible digital footprint?
What things did Felix say online that he should not have said?
47 David Ogunshola
www.earlycodingbook.com
Computer Programming, Digital Citizenship &
Analytical Thinking for Children
Operators
David Ogunshola
your learning journey
Project Ideas
in Scratch Cyberbullying
Page 45
Page 47
input & output
What all computers have in common
Even though computers may look very different, they all work in the same way. Whether they are
hand-held computers, desktops, laptops, robots, industrial computers or chips that work in other
machines, all computers perform four basic operations, and that is what makes them computers.
Input Processing
Input is what a computer receives before it Processing is whatever a computer does with
performs an action. Computers need something input. If you record your voice in Scratch, it is an
to work with and cannot do anything until they input but when you use Scratch to change the
have received input from someone or from pitch or speed of the recorded voice, you are
another program. processing the input.
Input can come from a keyboard, a mouse, a You can input five numbers into the computer and
microphone, a camera or sometimes even our ask a program to add them up. The process of
body signals. adding the input is called processing.
Storage Output
When a computer receives input, it can either Output is when a computer sends out information
keep it to process later, or when it is done that has already been processed. Computers
processing the input, it can keep it to be used output information differently depending on what
some other time. they were designed to do. Outputs can be text,
photos, videos, sound, interactions or signals.
Keeping something in the computer is called
storage. Every computer must have a memory Sometimes, the output from one program can
where it stores things. serve as input to another computer or program.
9 David Ogunshola
www.earlycodingbook.com
graph paper programming
Practice programming without a computer
In this activity, you will be practising how to think in algorithms and follow algorithms. The activity
looks similar to Pathway Ninjas, but it will require more focus, concentration and thinking. This is an
unplugged activity, so you do not need a computer.
You will be programming a graph paper by following the steps listed in an algorithm, and in other
cases, you will study a programmed graph paper and write out the algorithm that was used to
program it.
Move one Move one Move one Move one Color the Shows where
square up square right square left square down square to start
In Forward Programming, you program the graph paper by following the steps given in the
algorithm in the right sequence. In Reverse Programming, you study the programmed graph paper
and then re-create the algorithm that was used to program it.
5 David Ogunshola
www.earlycodingbook.com
Variables
Where programs store information that change.
Variables at work
Bob is playing a game called Ocean Stars in which he controls a fish to eat up as many star coins as
possible within an amount of time. Take a look at the two images below, the first was taken when Bob
was about to start the game, and the second was taken while he was playing the game.
Study the two pictures and list out the differences you observe.
11 David Ogunshola
www.earlycodingbook.com
sensing data
There are many in-built variables in Scratch. These are variables you do not have to create because
they are part of the Scratch program, however, they contain information that changes in different
situations. The variables created by the programmer are orange-coloured, while the variables that
come with Scratch are blue-coloured.
In the Sensing category, all the blue colored variables can also be used as data for operators.
Each of these will return a value which you can use in an operator.
The mouse x variable returns x value of the coordinate location of the mouse pointer.
As you move the mouse, the coordinate changes. This variable returns the location
whenever the mouse moves. mouse y returns the y value on the coordinate.
What other sensing blocks and in-built variables can you identify?
24 David Ogunshola
www.earlycodingbook.com
designing costumes
How to change sprite costumes to make them yours
Sometimes you want to use a sprite, but you don't like how it looks in the Sprites library. You may
want to modify it by changing its colour, look or shape. You may even want to create a new original
sprite that does not exist in the library. This is why there is a paint editor in Scratch. Select the
sprite you want to modify and click on the costume tab to open the editor..
Change color
Paint Fill
Text tool
Line Tool
Circle Shape
Square shape
35 David Ogunshola
www.earlycodingbook.com
strings in scratch
Operators in Scratch that work with strings
In Scratch, there are operators for working with strings. They are:
Knowing how to use these operators will enable you to become more
creative in your programming using Scratch.
21 David Ogunshola
www.earlycodingbook.com
conditionals
How computers make decisions
You will remember that we said computers are not smart and they cannot think like human beings.
They only follow instructions that they are given in a program. Have you ever wondered how
computers make decisions if they cannot think?
Condition Action
Condition
Action
When programmers code with conditionals, they can set different actions for the computer to take
when different conditions are met. This makes it look like the computer is smart and knows what to
do under every condition. There are no smart computers, only smart programmers. Whenever you see
a computer behaving very intelligently, it is running a program built by a very smart programmer.
25 David Ogunshola
www.earlycodingbook.com
broadcasts
How sprites communicate without touching each other
A broadcast is a message that is sent by one sprite and can be received by every other sprite.
It's easy for sprites to know when they touch each other and you can write code to run when
two sprites touch. Sometimes you want sprites to communicate with each other without
touching themselves, this is where you will need to use broadcasts.
When one sprite sends out a broadcast message, the broadcast can be programmed to
become an event that triggers a script in another sprite. This is very useful in games and
animations.
Using Broadcasts
33 David Ogunshola
www.earlycodingbook.com
creating animations
Creating interactive stories with Scratch
Animation usually includes using images in a sequence to create motion that looks like a video and using
sounds to add effects or create a conversation. This is how cartoons are made. The objects and
characters you see in cartoons are sprites, but through animation, you can make them move, talk and
interact.
2. Motion: Good animation will need to have sprites moving. You can't call a sprite standing in one place
talking to itself an animation. If you ever watched Tom & Jerry cartoons, sprites run, jump or even fly.
3. Conversation: there must be a conversation in good animations. You either get two or more sprites
to talk to each other, or you get a sprite to make a presentation or performance for the person
watching. The conversation can either be by voice or for the viewer to read.
4. Sound: without the right sound, your animation will be boring. You should use good sounds to keep
your animation alive and enjoyable.
5. Transitions: if you are telling a story, then the characters need to be moving from one scene to the
other. If you can make transitions look real , it will make your animation more enjoyable.
37 David Ogunshola
www.earlycodingbook.com
DON'T BE A CYBERBULLY
How we can all put an end to cyberbullying.
What is cyberbullying?
Cyberbullying
Bullying is when someone uses their power repeatedly Using digital devices, websites and the internet to
to hurt, harm or upset someone. People can be bullied intimidate, harm, and upset someone
physically or emotionally by calling them names or
saying things about them that hurt them or the
people around them. Bully
The person who is doing the bullying
Cyberbullying happens when someone uses the
internet to bully others. It is different from physical Target
bullying because: The person who is being bullied
1. It can happen anywhere and anytime making it
difficult for the target to hide or escape A Bystander
2. The bully can easily hide their identity so people A person who sees a bullying behavior and does not
don't know who they really are. do anything about it
3. Other people online can see what is happening
and either join in the bullying or do nothing about An Upstander
it. A person who sees a bullying behaviour and stands
up to defend the target
45 David Ogunshola
www.earlycodingbook.com
passwords
How private information are protected Digital Citizenship
Anything that is private on your computer, phone or on the internet should be available to only you.
Other people should only be able to see the things you choose to share with them. To protect those
things that are private, you need to lock them in a place that only you can access.
2. Money
People can move money from their bank accounts using apps on their phones or computers. If anyone
has access to your phone and those apps, it means they can move money from your bank account to
their own. To protect your money and keep it safe, those apps are protected with passwords.
3. Access to a computer
Sometimes, you do not want people to use your computer without permission, so to restrict them
from powering your computer, you can protect it with a password.
41 David Ogunshola
www.earlycodingbook.com
Computer Programming and Game
Development for Beginners
Logic
Games
your learning journey
Every algorithm or program can be represented using a flowchart created by combining different
symbols. Flowcharts are created by the designers or architects of the program. It is used to
communicate to another programmer what they have in mind. Inside each symbol, the action to be
taken will be written.
When an algorithm has been converted to a flowchart, any programmer can easily understand what it
is supposed to do and can use any programming language to build the program that can be executed
by a computer.
Process
The rectangle shape is used when there is an intruction
to carry out or something to do.
Decision
The diamond shape is used to represent decisions that
are usually boolean in nature.
Input or Output
The parrallelogram shows that the program is meant to
receive an input or display an output.
Arrows
Used to connect different shapes in the flowchart. It is
also called a connector
5 David Ogunshola
www.earlycodingbook.com
nested loops
Placing loops inside other loops
Inner loop
Outer loop
In a nested loop, the inner loop will run first, and when the inner loop is complete, the outer loop will also
run. For every time the outer loop runs, the entire inner loop will run again.
We use nested loops to repeat patterns that have other patterns in them.
Problem Solution
13 David Ogunshola
www.earlycodingbook.com
functions
Creating blocks that don't already exist
So far, whenever we need to run any script in our code, we have to join all the blocks that make it possible.
When we have some scripts that we want to use many times, instead of having to join many blocks over and
over, we can make it a function. Functions allow us to turn a script that may have 10 or 15 blocks of code
into just one single block.
Instead of doing that we can make this script into a block, and give it a name. Whenever we call that
block, this script would run. That is how functions work and they are used in every programming
language.
In Scratch, functions allow us to create blocks that don't exist in the Scratch library.
What we have now done is that we created a new block called "Spin Right" and we defined it with regular
blocks of code. Now we can drag the block 'spin right' into our code, and each time Scratch gets to that
block, it would run the script we defined.
15 David Ogunshola
www.earlycodingbook.com
Computer games
Creating awesome experiences
Computer games have become very popular, and children, young people and even adults love to play
games on their phones, tablets and computers.
Can you identify any of these games? Have you played any game that looks like them before?
If you can identify any of these games, write their names and describe how they are played.
Do you have a favourite game? Write the name of your favourite game and write out a few things that
make you love the game.
Game development is the process of creating and building your own computer games.
18 David Ogunshola
www.earlycodingbook.com
playability
What make a great game
Playability is the attribute of a computer game that makes people want to play it over and over
again.
There are games you just want to keep playing again and again without getting tired. Not all games are
that fun. Some games are boring and don't make you excited. A game has good playability when people
want to play it many times and they don't easily get tired of it. Sometimes, the game can be very simple,
but people love it. Such a game is said to have good playability.
Building a good game doesn't start with coding, it starts with planning
Before you start coding, you should have your entire game idea on a piece of paper. This will keep you
focused throughout the game development process
Characters Objects
David Ogunshola
www.earlycodingbook.com
Mechanics Rules
Mechanics are the things your characters can Rules are the guides for playing the game
do and how they interact with the objects.
The game's rules inform players what they’re
Think of them as the 'verbs' in your game. They allowed and not allowed to do. For example in a
include actions such as running, jumping, football game you are not allowed to touch the
shooting, flying, capturing, dodging or catching. ball with your hands. In a computer game, you
The mechanics are the things you program the cannot walk through walls or touch certain
player to be able to do. edges.
Goals World
The goals define what the player is trying to The world sets the environment in which the
achieve through the game. game is played.
Every game challenges the player to achieve The game can be played in space, under water,
something. The goal could be to escape an in a jungle or in a city. Determining where the
enemy, score as many coins as possible, win a characters would be is an important element of
race or survive for as long you can. Most games the game because it determines the feel and
have lots of small goals, such as unlocking doors atmosphere of the game. A game of aliens
to new levels or winning new vehicles or skills, all would best be played in space while a car race
in an attempt to achieve a bigger ultimate goal. could be played in a city or on roads.
Each mechanic should have a control trigger A good game should not be too easy or too
that makes the player do something. Depending hard. Usually, it should start easy and as the
on the device you are building a game for, your player masters the rules and mechanics of the
controls ould be keyboards, mouse, joysticks, or game, the difficulty should increase. You can
just touching the screen. The games is more increase difficulty levels bu increasing the
playable when the player feels in complete speed of enemies or objects, making enemies
control of the character. more powerful or making it harder for the
player to score points.
David Ogunshola
www.earlycodingbook.com
games & emotions
Determining how people feel when they play your game
How do you feel every time you play your favourite game?
Do you know that the developer of that game planned and determined how you would feel each time you
played the game?
As a game developer, you can also determine how people feel when playing your game. Different
emotions you can design into your game include excitement, joy, fear, relaxation, pressure, sadness and
more.
When playing your game, the player is entering into a new world, one that you the designer created. The
atmosphere you create in this world will determine how the player feels inside this world. If players
enjoy the atmosphere of your game, they will want to come in again and again.
If you are designing an adventure game, you could tell a story of a village
being attacked and how the hero's family was kidnapped. Now the hero
(who is the player) is on a mission to rescue his family and save his village
from the enemies.
This story gives the player a sense of mission and an emotional attachment to the game. It is different
is you create the same game but without the story.
Sound Effects
Sounds can be used to add effects to your game that affect the players
feeling. For example, each time a player scores a coin, you can play a winning
sound. The sound of winning a coin will make the player to try to win more and
more coins. You can also add a scary sound when an enemy is around so that
the player can sense danger.
All these sound effects contribute to how much players enjoy your game.
David Ogunshola
www.earlycodingbook.com
Backgrounds
Backgrounds are helpful in creating and defining the world in which the game is being played. You can use
backgrounds to change scenes, atmospheres and general player feelings.
Check the following game backgrounds. How does each of them make you feel? Where does the
background make you feel that you are? In which of them will ou prefer to play a game?
Speed
Manipulating speed has a way of making the player feel a sense of danger or more excitement. If the
game is designed to make a player dodge or escape enemy arrows, the game can start with the arrows
coming slowly and are easy for the player to escape. You can increase the difficulty of the game by
making the speed of the arrows increase.
More speed sometimes means more fear. Adding an element of variable speed in a game makes the
experience feel real for the player and as the speed increases, the player emotions are also controlled.
These two games have the same objects and platforms, but the colours in one make you feel like you are
in a cold snowy environment, while the other makes you feel like you are in a hot tropical environment.
The only difference between the two are colors.
David Ogunshola
www.earlycodingbook.com
MORE game ideas.
Attempt to create these games here
A chase game
In a chase game, one character chases after another
character who is controlled by the player. The goal of
the game is to make sure the player is not caught by
the chaser.
An educational game
Create a game where the player answers questions and solves problems in topics such as maths, science,
geography, history or general knowledge. The idea of the game is to generate different questions
randomly and give the player a very short time to answer the questions. The player scores a point for
every question they answer correctly and lose a point when they either answer wrongly or the time for
the question elapses.
A football game
You can attempt to make a regular football game or
some other kind of sports that simulates the real
game.
30 David Ogunshola
www.earlycodingbook.com
game planning
How to design your game before you start coding
Before you begin the design of your game, use this worksheet as a guide to plan out your the different
aspects of your game.
This is where you also define or include the mission of the game. For example;
The player is controlling a bat to ensure a randomly moving ball never touches the ground
The player controls a plate that catches apples falling randomly from the sky
The player is on a mission to kill all enemy aliens who are invading the planet
Rules Controls
Here you think about and define the rules for the game. What will be your controls?
E.g Define how the player will play
A player will have 5 lives the game.
The ball must not touch the ground
The enemy must not catch the player E.g
Players cannot walk through walls
Up Arrow = player move up
Be as creative as you can Space Bar = player hide
Key S = shoot
David Ogunshola
www.earlycodingbook.com
tinkering with
What is a Makey Makey?
Makey Makey is an invention kit.
It consists of a simple circuit board, alligator clips, and a USB cable. The circuit board allows
you to turn everyday objects into input devices used to control computers like your mouse or
keyboard by using closed-loop electrical signals.
Makey Makey is an extension in Scratch, but it works with a box of hardware that can be
purchased on the website www.makeymakey.com.
Makey Makey
What’s in the Box?
Board
Jumper wires
USB connector
Alligator wires
Plug the Makey Makey board into your computer using the USB cable. Then use the alligator clips to
connect the Makey Makey to conductive objects you want to turn into your keyboard!
A conductor is any object that can transmit electricity from one point to another.
Makey Makey works well with Scratch. You can use Scratch to make a program and use Makey Makey
to turn everyday objects into event triggers and controllers.
38 David Ogunshola
www.earlycodingbook.com
cybersecurity
Keeping yourself and others safe online
Cyber Attacks
There is a lot of activity happening on the internet, including learning, playing, business, trading, banking
and more. There are also people online whose mission is to harm others for different reasons. They are
called attackers even though many people call them 'hackers'.
A cyber attack is when someone deliberately and maliciously attempts to breach the information
system of another individual or organization.
There are many reasons why people engage in cyber attacks, some reasons include:
1. To make money: some attackers steal people's information to sell or to hold and ask for a ransom
2. Hacktivism: to make a political or social point
3. Espionage: spying on a competitor or another country's data to gain an advantage
4. Intellectual Challenge: to prove that someone's security is weak. Also called 'white hat' hacking
Phishing attackers make the communication look like it is coming from a trusted source, but when you
click on the link, it takes you elsewhere, and the goal is to scam you. Most phishing attackers pretend to
be banks, schools, shopping companies, or even your employer.
Identity Theft: identity theft is a type of crime in which someone's private information is stolen and
used for criminal activity either on the internet or in real life.
Clickbait: An image or headline that tries to get you to click on it, usually for advertising purposes
Financial Scams: these are attacks carried out by scammers with the intention of stealing money from
other people. It includes attacks on people's banks to move money away, or scams made to make
someone pay money into another account through false presence.
Malware-based attacks: Malware refers to "malicious software" and it is designed to disrupt or steal
data from a device, computer network or server. Attackers trick users into installing malware on their
devices. The malware gives the attackers access to your sensitive data and they can steal sensitive
information.
Password attacks: these are types of cyber attacks in which hackers try to guess, steal, break or
trick users into giving them their passwords. The attacker then takes over the email of devices of the
victim.
41 David Ogunshola
www.earlycodingbook.com
Online copyrights
The rights and responsibilities that creators have
Who is a creator?
If you have ever created something original like writing a story or
poem, making music, taking a picture or video of something and
uploading it to the internet, then you are a creator.
Copyright
Also, it is very likely that you have used someone else's creation
online. Legal protection that creators have
over the things they create.
Everyone who creates anything has the protection of the law
that recognizes them as the owners. This is called copyright.
Anybody who wants to use something they create is supposed to
take a permission from them or refer to them as the owner.
Important Vocabulary
Ownership of something you create, which gives you the right to determine how
Intellectual Property
others can use it.
To give credit to the person who created something, such as listing the author's name
Attribute
and the date, or a citation.
Copyright Legal protection creators have over the things they create.
A clear way to define the copyright of a creative work, so others know how they can
License
use it.
Fair use is the copying or using of copyrighted material for a limited purpose without
Fair Use having to first acquire permission from the copyright holder. Such use could include
commenting, criticizing or other transformative purposes.
46 David Ogunshola
www.earlycodingbook.com
PYTHON
Suitable for Primary and
Secondary Schools
David Ogunshola
LEARNING JOURNEY
What is Python?
Python is one of the leading programming languages in the world. It was created in 1991 by Guido van
Rossum. It is a high-level language, meaning the words and commands in Python are very close to human
language, making it easy to read, learn and understand.
There is a lot more you can do with Python. Some people even consider it one of the most powerful
programming languages today because of the variety of things you can do with it.
Step 1
Open any browser on your computer
and visit the Python website and
click on the download menu.
Note that you must be connected to the
internet.
www.python.org
Step 2
Select the latest version of python and download the
installation fil for the laptop type you use. The installation
file for Windows laptops would be different from that for
Apple laptops.
Clicking the download button will save the installation file to your
computer
David Ogunshola
www.earlycodingbook.com
Step 3
Run the installation file on your computer. You can do this by double clicking on the installation file that
you downloaded from the python website.
This process will install the basic version of the Python interpreter on your computer, allowing you to use Python to code
Other Options
If you do not have access to the internet to download the Python file, you can ask your teacher or
parents to help you do that.
Someone else who has downloaded the installation file can share it with you through a USD drive. Be
sure that you are getting the correct file for your computer type. You cannot install a Mac file on a
Windows computer.
The easiest way to launch Python however is to go to the app launcher on your
computer and search for "IDLE" and select the app with the Python logo.
IDE vs IDLE
IDE means Integrated Development Environment. IDLE means Integrated Development & Learning
This is any software that provides a programmer with Environment.
all the tools and resources needed to write code and This comes bundled with Python and provides all the
build their software and apps. Examples of IDE's are functionality for you to code in Python but also helps you
VSCode, Eclipse, Android Studio etc. in learning because it explains what bugs you have,
IDE's are used by professional programmers. allowing you to correct your mistakes.
David Ogunshola
www.earlycodingbook.com
python IDLE
Getting familiar with how Python works
Before we start learning a lot about how Python works, let's get a little bit familiar with the Python IDLE
Open Python IDLE on your computer and type out the following code
The response to that line of code you wrote is that the Python interpreter will write Hello Africa on a
new line, without quotation marks or the parenthesis. You will understand where all of them went shortly.
For now, you can try getting Python to write anything you want.
>>> 5 * 5
>>> 30 - 10
>>> 100 / 20
>>> 4 + 2 - 5 * 2
>>> 30 // 3
>>> 10 % 3
>>> 2 ** 5
David Ogunshola
www.earlycodingbook.com
datatypes
Knowing how to use data
Before a computer program can process data, it needs to know what type of data it is.
Datatypes are a way of classifying data so that the computer program knows how the programmer
intends to use the data.
2
Integers are whole numbers that have no
Integer 45
decimals or fractions
7560
Float 4.5
These are numbers that have decimals or
(also called Floating 2.0
fractions
Points) 34.876
45 = 45
A boolean is a statement or expression which
Boolean Joseph is a boy
has a response that is either True or False.
Today is Friday
The DataType usually determines how the computer processes each value. For example, integers and
floats are numbers, so you can add, subtract or multiply them. If you try to multiply a string by a
string, there will be a bug.
Many programming languages will require you to specify what datatype every variable is supposed to
contain, so that the computer knows what can be done with the variable and what cannot be done.
David Ogunshola
www.earlycodingbook.com
Arithmetic operators
Operators for working with numbers
Arithmetic Operators are the symbols with which we can perform operations on number
DataTypes such as Integers and Floats. We do not use them on datatypes that are not numbers.
Most of the arithmetic operators are used similarly to the way they are used in Mathematics with
just a few new ones you may not be familiar with.
The Floor Division and Modulo are the tricky operators. Let's explain them more.
20 // 6 20 % 6
When you divide 20 by 6, the answer is 3 When you divide 20 by 6, the answer is 3
with a remainder of 2. with a remainder of 2.
Floor division only takes the integer 3 Modulo only takes the remainder of 2
and discards the remainder. and ignores the main integer.
David Ogunshola
www.earlycodingbook.com
EVALUATION OPERATORS
Operators used to compare values
Just like Arithmetic operators are used to perform operations on numbers, Evaluation operators
are used for comparing values.
Evaluation Operators are Boolean in nature, meaning each will return a value of either True or False.
>
Will be True if the value on the left is 5 > 3: True
Greater Than bigger than the value on the right, if 2 > 1: True
not, it will be False 6 > 10: False
3 < 4: True
<
Will be True if the value on the left is 200 < 500: True
Less Than smaller than the value on the right, if 50 < 45: False
not, it will be False
==
Will be True only if the value on the 5 == 5: True
Equal To left is the same as the value on the 25 == 25: True
right 100 == 70: False
>=
Greater than Will be True if the value on the left is 24 >= 20: True
either bigger than or the same as 50 >= 50: True
or Equal to the value on the right 33 >= 40: False
<=
Less than or Will be True if the value on the left is 40 <= 40: True
either smaller than or the same as 30 <= 40: True
Equal to the value on the right 30 <= 20: False
!=
Will be True only if the value on the 30 != 20: True
Not Equal to left and the value on the right are not 2 != 4: True
same as 7 != 7: False
22 David Ogunshola
www.earlycodingbook.com
Creating variables
Getting comfortable with making variables
For example, every time someone writes an exam, they will score a certain amount of marks. As a
programmer, you can create a variable called "score" which will store whatever marks the student gets.
Whenever you want to make a reference to the marks the student gets, you just use the name of the
variable and Python will get whatever score is inside it. It doesn't matter if different users have
different scores, you don't have to change the content of your variable every time.
Variables are a very powerful feature of programming languages, without them, programming would be a
tedious task.
Every time you want to create a variable, just use the assignment symbol (=). The name of the variable is
on the left and the value of the variable is on the right. Think of it this way, the variable name is the
name of the container, and the value is what is inside the container.
age = 12
country = "Nigeria"
myweight = 23.5
David Ogunshola
www.earlycodingbook.com
how to name variables
Rules and best practices for naming variables
As the programmer, you have the liberty to choose any name for your variables. The name could be
anything meaningful and could be as long as you want it to be, but there are some rules you need to follow
for naming variables in Python. If your variable name violates any of the rules, the variable is illegal and you
will have a bug.
A variable name that does not violate any of the rules above is legal and will be accepted. Variable names
that break any of the rules will be considered illegal and cannot be used in Python.
Python Keywords
Python keywords are specially reserved words in Python that are used by the interpreter itself.
None of the Python keywords can be used as a variable because Python has already assigned another
meaning to them. If you try to create a variable with a keyword, you will get the following error
David Ogunshola
www.earlycodingbook.com
Can you tell if these variable names are legal or illegal?
Variable Name Is it legal or illegal? If it is illegal, explain why
4matrix = 77
player-speed = 500
player_name = "Spiderman"
distance_to_the_moon = 456343456
lives% = 34
Check out the following legal variable names. Which of them makes sense to you?
1. Choose a name that has a meaning close to the purpose of the variable. Names like age, surname,
firstname are variable names that can help another programmer know what you meant to do
with them.
2. While it's okay to use both UPPERCASE and lowercase, it is best to make longer variables
readable. You can do that either by separating words with an underscore or b using camel case.
David Ogunshola
www.earlycodingbook.com
modules & LIBRARIES
Accessing functions that have been created by others
A module is a file that contains a set of pre-defined functions that are related to each other.
A library is a collection of modules.
Modules and Libraries are similar to each other because they give the programmer a large collection of
already-created functions that makes programming easier and faster.
The functions in a module or library cannot be assessed directly by your program or by the Python IDLE. For
you to use them, you need to first import them.
When you import a module or library, you can then make use of all the functions it contains.
Importing a module
Python has many modules that contain a lot of helpful functions that perform many operations that enable
you to build programs faster.
To import a module, just write import and the name of the module.
To see the complete list of all modules in Python, write help('modules')
This code will display a list of all
>>> help('modules') Python in-built modules
When you run that code in your IDLE and there is no response, it means the module was successfully
imported. Now you can call any function that comes with the math module.
To display all the available functions in a module, just write write dir(module_name)
>>> dir(math)
This would list out all the functions in a list, but it doesn't explain what each of the functions does.
You can get help about every function in a module, write help(module_name.function_name)
28 David Ogunshola
www.earlycodingbook.com
arrays and indexes
Working with data sets and collections
Python has four types of arrays or datatypes that are used for storing collections of data. They are:
1. List
2. Tuple
3. Set
4. Dictionary
All four of them have their unique differences which you would learn as you progress.
In programming generally, we start counting our indices from the number zero (0) and not from the
number one (1). So the first item in an array has an index of zero.
Array item:
Index of item: 0 1 2 3 4
We can identify or call a particular item in a list by calling the name of the variable and the index in the
square bracket . In the first list we created:
myclass[0] = "David"
myclass[1] = "Ada"
myclass[2] = "Ibrahim"
Negative indexing
Python also allows you to call or reference array items from the end. We use negative indexing to achieve
this. Just like the first item in an array has an index of 0, the last item in the array has an index of -1.
The second to the last item has an index of -2, and it continues that way.
myclass[-1] = "Bola"
myclass[-2] = "Okon"
32 David Ogunshola
www.earlycodingbook.com
iteration: FOR LOOPS
Iteration, looping and repetitions
Iterations are like patterns that require you to do the same thing again and again.
For example, if you want to calculate the total score in Social Studies for 15 students in a class. You need
to add the test score and the exam score to get the total score. You will have to perform that same
operation for each of the 15 students in that class to be able to have everybody's total score. That's an
iteration - you are performing the same task, but doing it multiple times.
Whenever you need to solve a problem that requires an iteration, then you need to use a loop.
In most text-based programming languages, there are two popular types of loops:
FOR LOOP
WHILE LOOP
For Loop
A for loop is used for iterating over a sequence which could be a list, tuple, set, dictionary or even a
string.
The for loop allows you to execute a set of statements once for each item in a list or sequence. For
example, if you have a list of students and want to print a statement for each student, you can use a
for loop.
The list runners is the iterator, x is just an indexing variable and could be replaced with anything.
Also pay attention to the colon and the indentation.
An object is said to be iterable if it is possible to run an iteration on it. If the items in the object can
be converted to an array, then it is iterable. Generally, a string is also iterable because the
characters in a string can be turned into an array.
Many of the operations you can perform on lists can also be performed on strings.
37 David Ogunshola
www.earlycodingbook.com
show your skills
Programming challenges for you to solve
Your challenge as you learn to code in Python is to be able to solve all the problems on this list. As you learn
more and develop your skills, always come back to the problem list to see if you are able to solve a new
problem. Once you have successfully solved a problem, tick off the "solved" box.
The goal is to be able to solve every problem on this list.
Challenge Solved
Write a function called reverse() that takes a string as an argument and rewrites it
1
backwards. E.g you pass "hello" the function and it returns "olleh"
Create a function that asks the user for two numbers and prints out the sum,
2
difference, product, and quotient of those numbers.
Create a program that takes a list of numbers and returns the sum of all the even
3
numbers in the list.
4 Create a program that takes a list of strings and returns the longest string in the list
Write a program that generates a random number between 1 and 100 and asks the
6 user to guess it. The program should provide feedback on whether the guess is too
high or too low until the user guesses correctly.
Write a function that takes a list of integers and returns a new list with all the duplicate
7
values removed.
Write a function that takes a list of strings and returns a new list with all the vowels
8
removed from each string.
Write a program that calculates the sum of all even numbers between 1 and a given
9
number.
Write a calculator program that asks a user to enter two numbers, select what
10
operation they want to perform on it and it returns the answer.
Create a password generator function that suggests a password for a user that meets
11 the requirements of having 8 characters, has both numbers and letters and special
characters.
12 Create a Python function that tells the current time and date each time you call it.
Share your codes, post your challenges and connect with other programmers in our online coders
community.
www.earlycoding.online/community
48 David Ogunshola
www.earlycodingbook.com
Additional Support
Teacher's Training &
Certification
We have developed a training and certification program that equips
teachers to use Early Coding for Kids books and curriculum to teach
learners of all ages.
Training Options
Online Version; Link on the book website
Offline Version: available on demand, for a minimum of 50 persons
Complimentary Training: Schools get FREE training for 1 teacher for every 250 books bought
Place Your Orders
Online
www.earlycodingbook.com
Phone + WhatsApp
+2349036559150 | +2348077544056
Africa's leading coding and startup school for children
...on a mission to lower the age of innovators in Africa
www.earlycoding.online