Vous êtes sur la page 1sur 62

POWER of PATTERNS

Rane Anderson
POWER of PATTERNS

Rane Anderson
Consultants
Timothy Rasinski, Ph.D.
Kent State University
Lori Oczkus, M.A.
Literacy Consultant

Publishing Credits
Rachelle Cracchiolo, M.S.Ed., Publisher
Conni Medina, M.A.Ed., Managing Editor
Dona Herweck Rice, Series Developer
Emily R. Smith, M.A.Ed., Content Director
Stephanie Bernard/Noelle Cristea, M.A.Ed., Editors
Robin Erickson, Senior Graphic Designer

The TIME logo is a registered trademark of TIME Inc. Used under license.

Image Credits: p.4 Scott Olson/iStockphoto.com; pp.4–5 NG Images/


Alamy Stock Photo; pp.6–7 hocus-focus/iStockphoto.com; p.18 Hans
Hillewaert, used under Creative Commons BY-SA 4.0; pp.19, 20–21,
22–23, 25, 28–29, 33, 35, 36–37, 40 Scratch is a project of the Lifelong
Kindergarten group at the MIT Media Lab. See http://scratch.mit.edu; all
other images from iStock and/or Shutterstock

Note: The answers to the mathematical problems posed throughout the


book are provided on page 48.

Library of Congress Cataloging-in-Publication Data


Names: Anderson, Rane, author.
Title: Power of patterns : coding / Rane Anderson.
Other titles: Coding
Description: Huntington Beach, CA : Teacher Created Materials, [2017] |
Audience: Grades 7 to 8. | Includes index.
Identifiers: LCCN 2016047694 (print) | LCCN 2016056196 (ebook) | ISBN
9781493836253 (pbk.) | ISBN 9781480757295 (eBook)
Subjects: LCSH: Computer programming--Juvenile literature.
Classification: LCC QA76.6 .A4697 2017 (print) | LCC QA76.6 (ebook) | DDC
005.1--dc23
LC record available at https://lccn.loc.gov/2016047694

Teacher Created Materials


5301 Oceanus Drive
Huntington Beach, CA 92649-1030
http://www.tcmpub.com
ISBN 978-1-4938-3625-3
© 2017 Teacher Created Materials, Inc.
Table of Contents
A Coder’s Dream . . . . . . . . . . . . . . . . . . . . . 4
Coding Basics . . . . . . . . . . . . . . . . . . . . . . . . 6
Coding Languages . . . . . . . . . . . . . . . . . . . 12
Basics in Scratch . . . . . . . . . . . . . . . . . . . . . 20
Boolean Expressions . . . . . . . . . . . . . . . . . . 26
Conditional Statements . . . . . . . . . . . . . . . . 30
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Evolution of Code . . . . . . . . . . . . . . . . . . . . 42
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Check It Out! . . . . . . . . . . . . . . . . . . . . . . . . 46
Try It! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
About the Author . . . . . . . . . . . . . . . . . . . . . 48

3
A Coder’s Dream
Imagine creating a useful tool that will make life
better for thousands of people simply by your writing
words on a page. With computer programming, you
don’t have to imagine it; you can make it happen.
Computer programming helps turn dreams into reality.
Someone once dreamed of sharing thoughts, photos, and
messages with people around the world. And now, people
can do that through social media. Gamers once dreamed
of adventuring through uncharted territory. So computer
programmers, often called coders, developed virtual
worlds. Employees at NASA once dreamed of exploring
the surface of Mars. They programmed robots that can
travel there and collect environmental data. Each of these
innovations depended on computer programming to
bring it to life. From social media to artificial intelligence,
coding can make our wildest dreams come true. The only
limit is our imaginations.

nce for A ll
Computer Sciearack Obama’s 2016
nt B
In Preside ress, he
o f th e Union Add
State bring
d his plan to
an n o u n c e all schools
science into said that
computer e
es States. H els
in the Unit g ra d e lev
f all
students o ls to
rn the skil
should lea technologie e,
s. He
te d ig it a l
crea scienc
computer
considers a b asic skill.
c lu d in g coding,
in

4
That’s So Coded
Most electronic objects people use
on a daily basis require coding. Vide
o
game consoles, cell phones, tablets,
pacemakers, alarm clocks, and so
many other items rely on coding.

the Curiosity Mars rover

5
Coding Basics
Many people spend several hours each week in front
of computer screens, tablets, or mobile devices. Screen
time provides entertainment, keeps us connected with
family and friends, and is a great outlet for learning about
virtually anything. All of this screen time takes place on
just the “surface” of computer coding, in what’s called the
graphical user interface (GUI). GUI is often pronounced
like the word gooey by those in the coding world.
But hidden behind the GUI is a complex world of
words and symbols that build the apps, software, and
websites people love. These words, or lines of code, bring
computers and other electronics to life. Coding helps to
create all kinds of programs, from role-playing games to
the programs used by medical devices that might one day
save your life.

Medical Devices
Devices such as heart rate monitors,
sleep sensors, and blood pressure
machines run on computer programs.
Other programmed devices take more
active roles in maintaining the health
of patients. For example, insulin
pumps and other drug-delivery
devices get the right amounts of
medicine to patients right when
they need it most.

6
Matched!
If someone wan
ts to donate a
family membe kidney to a
r but is not a go
there’s a compu od match,
ter
This program ke program that can help.
eps track of po
and searches fo tential donors
r other viable
paired-exchang matches. In a
e donation, whe
is found, the do n a match
nor can give a
that person an kidney to
d hopefully ea
a viable kidney rn
for his or her
family membe
r in return.

7
Computer Recipes
If you wanted to bake cookies, how
would you begin? You might start by
gathering all the necessary ingredients, such
as flour, butter, sugar, eggs, and chocolate
chips. But you would also need the recipe
to tell you how to bake everything once it’s
combined. After all, the ingredients can’t bake
themselves. That’s exactly how computers and
other electronic devices work. Electronic devices
possess all the ingredients needed to perform impressive
tasks. But by itself, an electronic device cannot accomplish
much besides basic arithmetic. Electronic devices need very
specific instructions, like a recipe, to complete complex
operations. That’s why coders write source code.

The Source Code Story


Computer magic begins with a coder dreaming up an
idea. But to get that idea to actually work on a computer
or another electronic device, the coder must first write the
source code. The source code contains the step-by-step
instructions written in words, numbers, and symbols that
will make a program run.
8
PE MDAS
When we start to evalua
te an expression, we mu
order. This is known as st follow a specific
the order of operations.
the saying “Please Excuse You might have heard
My Dear Aunt Sally.”
Please Parentheses
Excuse Exponents
My Dear Multiply/Divide (left to
right)
Aunt Sally Add/Subtra
ct (left to right)
To correctly solve an exp
ression, follow the precis
of the order of operatio e instructions
ns. Don’t ignore the left
requirements because, to right
if you do, you’ll get the
answer. A computer pro wr on g
gram also relies on precis
instructions that follow e
a specific order.

PEMDAS in Action
(18 + 2 ∙ 3)
22
Evaluate this expression in whatever order you see fit, completely
ignoring the PEMDAS rule. Try it again using a different order. Lastly,
solve it using the order of operations, and check your answer on
page 48. This should illustrate that very different answers will result
based on the order in which you solve. But what matters most in
this problem is finding the correct answer. What do you think would
happen if the source code of a program were written out of order?

9
Route Algorithms
Type in an address on a map or GPS application, and it will search
for the shortest, fastest route available. But how exactly does
the application find the best route? Computer programmers use
algorithms to solve problems like this and include them in the source
code of programs.

A lgorithm for A rea countered an algorithm in your


ably en calculate the
You have prob ple, the steps to
as s. Fo r ex am
math cl m:
are an algorith
area of a circle
e circle.
re the radius of th
1. M ea su dius by itself ).
re th e ra di us (multiply the ra
2. Squa (3.14).
the result by π
3. Multiply
2
A=π×r
r

If the radiu
s of a circle
distance fro is the
m its center
edge and th to the
e diameter
what is the is 2r,
area of a ci
a diameter rcle with
of 4 feet?

10
An aMAZEing Escape!
Imagine that you need to discover the quickest route off your school
campus. Create an algorithm that helps find the fastest way out of the
school maze. Search for possible routes while also determining the
best route for immediate escape. Then, generate your route algorithm
by writing instructions using directional words like right, left, up, and
down. Also include the number of blocks to travel per move. Format
your instructions in the following style:
Walk [direction] [#] space/s

End

Start

End 11
Coding Languages
Hello! こんにちは! Bonjour! Habari! Ciao! !‫שלום‬
Similar to people, computers “speak” many different
languages. In the early days of coding, computer
programmers used machine code to write computer
commands. This difficult language consists of dizzying
strings of 0s and 1s called binary numbers. It’s challenging
for people to read and write machine code. That’s partly
why hardly anyone uses it today. But it remains the only
language a computer’s processor can read entirely without
the assistance of another program. In fact, all programs
must be translated into machine code to run.
High-level languages account for a large percentage
of the languages used to write programs. These languages
use dictionary words and syntax that are more easily read
by humans. So not only is it easy for people to read and
write, but it’s also much simpler for coders to express
complex ideas within the source code. That opens a world
of possibilities.

C++
C++ is a relatively old language, but it is
a workhorse in the programming world.
It excels at creating robust, precise, and
high-performance programs. It is the
language of choice for video games and
financial and manufacturing systems.

12
Spot the Code
Practice distinguishing between machine code
and different high-level languages. Can you spot the
differences?

resultSet = db.executeQuery(select *
from users where Fname=‘john’);
00010101101011101010100100100101
String lastName = resultSet.
getString(“Lname”);
00000101110101010110001101011001

Python®
Python is a general-purpose, high-level programming
language. It has very simple syntax, which makes it easy
to program. It is also open source, which means a user can
download the compiler and tools for free. Python can
be used to write application software and to script the
sequence of instructions needed for a web application.

13
Source Code Translators
People can travel from one side of the world to
the other in under a day. Often this means travelers
are suddenly immersed in a country where potentially
nobody else speaks their native language. How might a
traveler order dinner at a restaurant in a foreign country?
How would he or she locate a hotel? Many people use
translators to convert words from one language into
another. The technology company Waverly Labs has
designed an earpiece system called Pilot®. Two people who
speak different languages each wear an earpiece. Using a
speech recognition app, the earpiece translates the dialogue
directly into the users’ ears.
Computers also rely on translators to convert the
source code of high-level languages into machine code. In
computer programming, there are two types of translators:
compilers and interpreters. Simply put, a compiler
translates an entire program and then executes it.
An interpreter translates each line of code and
executes them one by one.

14
Have you ever noticed a computer file that ends in
the extension .exe? This file contains the machine code
of a program that has been compiled from source code.
Compiled files only run on the type of computer they were
designed for. For example, you can’t run an .exe file on a
Macintosh operating system because .exe programs were
designed to run on Windows machines.
Interpreters translate source code into machine code as
the program runs. Interpreted code runs on many types of
operating systems. A versatile language such as Java® is
compatible with thousands of devices from computers and
phones to coffee makers and cars.

Java
Java is an interpreted language, which
means that Java code can run on any
device supporting Java. According to
Java’s publisher, Oracle®, over five billion
devices run the language platform. Java
has similar syntax and capabilities to
C++, but it runs much slower because it
is an interpreted language and only runs
one line of code at a time.

15
The Pre-code Code
If you have to write an essay, a book report, or a
research paper, what’s your prewriting strategy? Most
writers begin the writing process by brainstorming and
outlining their ideas. Many beginning coders follow this
same process.
Writing source code in a high-level language takes a lot
of time and patience. So coders often begin brainstorming
or detailing their ideas for programs using a fake language
called pseudocode. Pseudocode is a simplified version of
high-level language that’s used for program planning rather
than execution. Think of it as a rough draft. It allows a new
coder to translate an idea into code without focusing too
much time or energy on writing perfect source code. Take a
look at this pseudocode for a hypothetical quiz program:

Ask User “Who famously said ‘I’m


the president of the United
States and I’m not going to
eat any more broccoli’?”
option “A) Barack Obama”
option “B) Jimmy Carter”
option “C) George H. W. Bush”
option “D) Teddy Roosevelt”
Get user’s answer
If the answer is C, Then
output “You got it right!!”

16
Scratch ®
Some code
rs use visua
languages. l programm
In a visual ing
coders can programmin
manipulate g language
program gra elements o ,
phically. In f the
visual prog Scratch, on
ramming la eo
create gam nguages, use f many
es, tell anim rs can
simulations ated stories,
using code and design
blocks and
pictures.

Here’s a n Idea! uding teachers—use


incl cepts.
Some users— m a th e matical con
p la in
Scratch to ex illustrate ma
th will
tc h to t
Usin g Sc ra ging concep
e ti m e s m a ke a challen rs
som ratch use
derstand. Sc
easier to un mes to
ls o cr e a te their o n ga
w
can a ills.
p ra ct ic e ce rtain math sk
help
17
Coding Rules
Every written language, including English, comes
with a set of rules to follow. In school, students learn
to capitalize the first word of every sentence. We also
learn to complete each sentence with punctuation such
as a period, an exclamation point, or a question mark.
Students also learn that sentences require a subject and
a predicate.
Just as the language rules for Japanese and English
are different, each programming language also has
its own unique syntax. And if the rules of whichever
programming language being used are not followed,
the program will either do something you don’t want
it to do, or it may not run at all. Learning to use a
programming language can be as difficult as learning a
foreign language. Both take a considerable amount of
time and practice to achieve fluency.

Rosetta Stone Stone in 1799


e di sc ov er y of the Rosetta
Th Egyptian
sc ho la rs to translate
al lo w ed Ptolemy V
ph s. A decree by King
hi er og ly same stone
yp t w as ch iseled into the
of Eg s, once
re e ti m es : on ce in hieroglyph ce in
th d on
motic script, an
in Egyptian de ri ng th e three
t Gr ee k. By compa
an ci en lars could
io ns , tw o of which the scho
ve rs finally
de rs ta nd , th ey were able to
un s.
tian hieroglyph
translate Egyp

18
These four languages ma
y look different,
but they all have the sam
e output.

Java for (int index = 1; index <= 5; index++)


{
System.out.print(index + " ");
}
System.out.println();
Python for index in range(1, 6):
print index,“ ”
VisualBasic For index As Integer = 1 To
5
Debug.Write(index.ToString & “ “)
Next
Debug.WriteLine(“”)
Scratch

Output for 1 2 3 4 5
all:

o What differences do you notice among


the various source code examples?
o What are some similarities between
the different source code examples?
o Which of these languages do you think
would be easiest to learn, and why?

19
Basics in Scratch
New coders often use Scratch as a learning tool and as a
gateway to the more difficult high-level languages. Scratch
uses color-coded “blocks” of code—rather than plain text—
to create instructions. Using the blocks, coders can design
all sorts of programs. Some examples include interactive
tools for learning, games, animations, and art. Unlike
textual coding languages, visual programming languages
allow coders to drag and drop premade sections of code.
This allows coders to build programs as if they were
building with toy blocks. In this way, the different shapes
and colors visually show the necessary syntax.

The menu is where you can save a program,


create a new program, and so on.

Switch from one category to another to find


different code blocks (called scripts) that can
then be dragged and dropped onto the stage.

20
The Scratch GUI
Codes can program sprites to accomplish many
different types of things, such as walking, dancing, talking,
or embarking on an adventure.

Click this tab to add sounds to accompany


different parts of your program.

Drag and drop blocks of code on the stage to


arrange instructions for your program.

Scratch Online
Scratch allo
ws coders to
program m share their
asterpieces
community. in an onlin
It provides e
the opportu cod
nity to learn ers with
teach some from others
thing new, ,
someone e or be inspir
lse’s progra ed by
m.

21
Variables
Have you ever programmed your favorite station into a
car radio? If you have, then you have already used one very
basic component of coding called a variable. A variable
stores a value, such as a number or word, which represents
something meaningful. People store these values and can
manipulate them later. For example, you can set a pop
station this year and change it to a rap station next year. The
numbers of the radio stations are stored in variables.
In mathematics, variables are single letters used to
represent unknown values. What are the variables in the
equation below?

y = 8x–21

When coding, it’s


Va ri able s in Sc ra tch best to come up
e five different
In Scratch, there ar with a descriptive
to variables.
blocks that relate name for what
the variable will
represent.

22
In many video games, a health bar tracks a player’s
health. Obstacles or events may occur in the game that
either injure or restore the player’s health. Below is what
a health bar might look like for a hypothetical game
written in Scratch. In this game, touching lightning will
hurt a player’s health. In order for the computer to be
able to remember this value and keep track of how it
changes, it’s stored in the variable.

23
Input and Output
Think about your favorite computer games, video
games, or board games. Now, imagine that suddenly you
cannot play them anymore and you’re only allowed to
watch. How boring is that?
In coding, input is a user interacting with a program,
and output is what happens as a result of the input. Think of
input and output as having a cause-and-effect relationship.
Different languages have very different ways of getting
input into programs. In one program, an interaction
could be the click of a button or the typing of a word
into a pop‑up. By making a program interactive, you can
complete more interesting tasks.

Input and Output with GUIs


In the old days, computers had text-based interfaces
where users could only read plain text on a screen and
type text commands on the keyboard. But now, with GUIs,
a user can click, tap, and drag buttons or images on the
screen to tell the program to do something—this provides
tons of great input and output.

Ga rba ge In, Ga
If a progra
rb a ge Out Pr incip
m prompts le
between 1 “enter a n
and 10” an umber
entered in d “hello” is
stead, it w
meaningle ill likely giv
ss result. O ea
working all r it might
together. In stop
helps avoid put valida
this proble tion
m.

24
Input a nd Output
Scratch’s GUI
in S cratch
makes it easy
output. The fo to set up inp
llowing code ut and
name, greet will ask for th
the user, and e user’s
to find out h then perform
ow many lett a calculation
ers are in the
user’s name.

25
Boolean Expressions
Imagine that you get an allowance every Friday
at 6 p.m. To get that allowance, you must first meet
certain conditions ahead of time, such as completing all
homework and chores. As 6 p.m. on Friday rolls around,
your parents will verify whether the responsibilities have
been completed. There are only two options: yes or no.
In computer programming, a Boolean expression
establishes whether something is true or false. And the
answer to the question helps the computer decide how
to proceed. In the allowance example, a true or false
question will indicate how to proceed: Should your
parents award the allowance or not? In other words, a
Boolean expression is like a test that requires two values
to compare and an operator to define the test.

26
Comparing Values
This is what a Boolean expression looks like using a
mathematical test:

x<5 x < 5

This compares two values,x x >and


5 5.

Assuming that x represents x an


= unknown
5 integer, this
statement will determine if the value of x is 4 or lower.
If it is, this statement will evaluate to true. Otherwise, it
will evaluate to false. x < 5

x>5 x > 5
x < 5
x = if5 the value of x is 6
This statement will determine
or higher. x > 5

x == 5 x = 5

This statement will determine if the value of x is


exactly 5.

T he Double Equa
Notice that
l Sig n
the last exam
programmin ple uses a d
g languages, ouble equal
value of 5 in a single equ sign. In most
to the variab al sign (x = 5
will test to se le x. A double ) stores the
e if two valu equal sign
es are equal.

True or Fa lse?
t greater than 1, is
If x is less than 4 bu
tion true or false?
the following equa
7 (x + 2) ≥ 42
27
Conditional Booleans determine if a certain condition,
or circumstance, has occurred. The bright blue “touching
edge” Boolean block (the hexagonal shape indicates it is a
Boolean block) tests to see if the car has reached the edge
of the stage. If it has reached the edge of the stage, the
program will then turn the car around.

28
Comparative Booleans compare the values of two
different numbers. Usually, they compare the value of a
variable to a static value, a value that doesn’t change.

The green Boolean


block tests to see if the
value within the variable
“answer” is equal to “blue.”

Cond itiona l Boole an Block s in Sc ratch


pressing
This block tests if the user is
a certain key on the keyboard.
pressed down
This block tests if the user has
on the mouse button.
touching the
This block tests if the sprite is
n box.
object selected in the drop dow
touching
This block tests if the sprite is
.
any object of the color shown

29
Conditional Statements
You probably use conditional statements every day
without even realizing it.
• “If the weather is nice, then I’ll go to the beach today.”
• “If I win the tickets, then I’ll take a friend to the concert.”
• “If I get an A on this exam, then I’ll get an A in the class.”
In coding, a conditional statement, also called an
if‑then statement, instructs a program that if x is true, then
y should happen next. If this sounds similar to Boolean
expressions, that’s because it is. Boolean expressions play a
large role in conditional statements.
Think back to the example about getting an allowance.
If the right conditions were met (i.e., homework and chores
are complete Friday before 6 p.m.), then your parents give
you the allowance money. Actually, giving the money
would be what your parents—or “the computer”—decide
to accomplish next. In other words, if something is true,
the computer will be
instructed to then
run a specific block
of code.

30
BA SIC Co de Fu n
Imagine you are writing a
quiz program. First, you wo
ask the user a question. You uld write code to
would also write code to pro
with four possible answers. vide the user
Then, you would want to che
correct answer is entered. ck to see if the
Here is the BASIC code for
if you can get it right. This this scenario. See
code shows the user select
ed “C”:
print “A TV advert
isement claims that
5 out of 6 dentists
recommend Acme
toothpaste. If 900
dentists were
surveyed, how many
recommended Acme
toothpaste?”
print “A) 750”
print “B) 1,080”
print “C) 300”
print “D) 600”
answer = prompt(“Wh
at is your answer?”
If (answer == C) Th )
en
print “Your answer
is C.”
End If

o What is the if-then component of the


above code?
o Do the math to determine if the correct
answer is C.
o What might happen if the user gets the
answer wrong?

31
The If-Then-Else Statement
An if-then-else statement builds on an if-then statement.
An else statement is used to do something if the condition
in the if-then statement ends up being false. We use these
statements in everyday situations.
• “If the weather is nice, then I’ll go to the beach today, or
else I will go swimming at the gym’s indoor pool.”
• “If I win the tickets, then I’ll take a friend to the concert, or
else I will split the cost of the extra ticket.”
In the quiz program example on the previous page, the
user selected C as the answer, which is, in fact, incorrect.
To better explain why, here’s a breakdown of the statement:
Of the dentists surveyed, 5 out of 6, or about 83 percent,
recommend Acme toothpaste. So, to solve this word
problem, we multiply 0.83 by 900.
(0.83) × (900) = 750 dentists
Therefore, the correct answer is A.
When writing a quiz program, it is essential to account
for the user’s correct answers as well as incorrect answers.
To do this, the if-then statement can be rewritten like this:

If( answer == A ) Then


print “Your answer is right.”
Else
print “Your answer is wrong.
The correct answer is A.”
End If

32
Problems with Then
Sometimes, coders fail to tell the program wher
e
the if-then statement ends. But in programs such
as Scratch, it’s easy to visually identify where
it should end. For instance, the orange if-then
code block wraps its “arms” around the section
of code that will run if the statement is true.

33
Loops
Computers complete repetitive tasks quickly and
efficiently. To make this happen, coders break down
the tasks they want to accomplish into sets of repetitive
steps that can leverage the computer’s power. When
making a peanut butter sandwich, one step is “spread
the peanut butter.” But this single part of the process
can be broken down into many substeps:
a. Insert knife into peanut butter jar.
b. Scoop up peanut butter.
c. Remove knife from jar.
d. Spread peanut butter onto bread.
To people, it’s obvious to only spread enough peanut
butter to cover the bread. But computers need extremely
specific instructions. A computer would need to know
exactly when to start and stop spreading the peanut
butter. If a computer is just told, “spread peanut butter
onto bread,” it will go into an infinite loop. It doesn’t
know when to stop or even if it should ever stop.

34
Infinite loops could be problematic if the task a
computer is told to do isn’t meant to repeat forever.
The computer will get stuck in the loop and never
move on to the next task. So coders need to indicate
an exit condition, otherwise the loop will remain
stuck infinitely repeating the same step.

Loops in Scratch
Scratch clea
rly identifie
For example s different ty
, one loop m pes of loops.
while anoth ay be labele
er may be la d “forever”
hexagonal sh beled “repe
ape will ind at 10.” A
that will rep icate a Boole
eat until the an test block
Boolean beco
mes true.

35
Do-While Loop
In a do-while loop, the computer performs each step
of the instructions only once, and when it reaches the end
of the instructions, the computer checks the exit condition.
If the exit condition is true, the computer repeats the
steps. Upon reaching the end of the steps, it once again
checks the exit condition. If the exit condition is still true,
it repeats the process again. However, as soon as the exit
condition is false, the program exits the loop and proceeds
to the next statement.

Do-W hile Loop in Pseudocode


Do {
a. Insert knife into peanut butter jar
b. Scoop up peanut butter
c. Remove knife from jar
d. Spread peanut butter onto a slice of bread
} While (Bread is less than completely covered)

In the example above, an exit condition has been added


to the end of the instructions. In doing so, spreading peanut
butter is now a do-while loop. In the example below, the lack
of an exit condition means the car will keep driving back
and forth forever.

infinite loop example

36
Loops in Scratch
Let’s take a look at the code used to create loops in
Scratch. In this example, the “forever” loop was replaced
with the “repeat until” loop. This means that now the car
will continuously move only until it touches the edge of
the stage, and then it will exit the loop. Then, the following
commands will make the car turn and drive up the street a
little just before the program ends.

ple
“repeat until” loop exam

37
Debugging
When you finish coding your very first program,
you’ll undoubtedly expect to see the miraculous results
of all the time and effort devoted to the task. So you sit
back and expect to watch your masterpiece at work. But
then . . . nothing happens. Or maybe something does
happen, but it goes very, very wrong.
This is a familiar story that many coders,
professionals included, could tell, and it’s the reason
debugging is such an important element of computer
programming. Coders will sometimes spend hours
trying to determine why programs don’t run or why
there are strange glitches that are not supposed to exist.
Troubleshooting what the problem is and then how to
debug it requires patience and perseverance.

Find the Error


Locating the error wi
thin code requires th
thinking skills needed e same critical-
to find an error in a
Take a moment to pr math problem.
actice those skills he
the following problem re. The answer to
is incorrect. Try to loc
ate the error.
(3a2 + 6a − 2) + (2a2
− 8a − 7)
3a2 + 6a − 2 + 2a2 −
8a − 7
5a2 + 6a − 2 − 8a −
7
= 5a2 − 2a − 5

38
The General Idea
Unfortunately, there’s no foolproof, step-by-step
method to debug a program. The process of debugging
can be lengthy and often includes a lot of trial and error.
To begin debugging, consider the following questions:
• Are the commands logical?
• Are important commands missing within the code?
• Are any commands out of order?
• Are there commands inside an if-then statement
that should be outside it or vice versa?

Ask the Community


When all else fails—ask a friend. If the program you
work with is shared with an online community, chances
are many coders will come to the rescue. This shouldn’t
be the first step in the debugging process,
however. Trust yourself, and put in the time
and patience. It’ll make you a better coder!

Practice, Practice, Practice!


Scratchers post debu
gging activities onlin
for you to practice yo e
ur debugging skills.
Do a search on the Sc
ratch website for
debugging activities
, and you will find ma
Also, just as you migh ny.
t ask the community
to help debug your pr
ogram, you can also
practice your troubles
hooting skills by
helping other coders
who ask for help.

39
Troubleshooting the Code
In the program below, you must guess a number between 1 and 10. In
turn, the sprite will declare whether your answer is too high or too low,
but this part of the code doesn’t work consistently. Review each line of
the code to troubleshoot the problem.

1
2
3
4
5
6
7
8
9

10
11

12

13

40
The Fix
o It’s efficient to begin troubleshooting the part of the code that
presents an obvious problem when the program runs. Since the
problem concerns the less than or greater than function, the
debugging process begins there.
o Line 8 checks if the user’s answer is greater than the “random
number” chosen by the program. If it’s greater than the “random
number,” the program proceeds to line 9. Otherwise, it skips to
line 10.
o Line 9 tells the user that he or she needs to guess a lower number.
o Line 10 checks to see if the user’s answer is greater than the
“random number,” which is the same as line 8.
It looks as though two if-then statements check for the same condition.

One needs to check for [answer < number] and the other


needs to check [answer > number]. Therefore, Line 10
should be changed to “if answer < number then.”

41
Evolution of Code
Computers today accomplish millions of steps in
the blink of an eye, and computer programmers have
designed each one of those steps. Even doing something
as simple as logging on to a website requires hundreds of
concepts written by thousands of different programmers.
Programmers have dreamed of and built remarkable tools
to help the world become a better place. As a result of their
hard work, people have been able to crack enemy ciphers
during World War II, send rockets into space, and connect
nearly every corner of the world to the Internet.
It’s now up to the future generation of coders: you.
You have the power to continue shaping the world through
code. What great challenges can you think of? And how
might a computer program solve those challenges? Always
dream big, but remember that from humble beginnings
come great things. This means that it’s all right to start
small. While you learn to code, try to imagine how you can
make a difference at home or at school. Even small steps
mean you’re moving in the right direction.

The Workplace Fun Zone


try to attract
A huge number of companies
gra mm ers by
talented computer pro
e as inte rac tive and
making the workplac
sof twa re and Int ernet
fun as possible. Many d
ak roo ms full of foo
companies stock bre
e gam e roo ms for
and drinks, and provid
e even have
foosball or table tennis. Som
e nap s during breaks.
areas for coders to tak

42
A Wise Messa ge e secrets of
ant to uncover th
“Whether you w ue a career
you want to purs
the universe, or computer
t centur y, basic
in the twenty-firs to learn.”
an essential skill
programming is
physicist,
king, theoretical
—Stephen Haw d author
cosmologist, an
43
Glossary
algorithms—step-by-step innovations—new ideas,
procedures used to solve methods, or products that solve
problems a problem
application—a software program input validation—a series of
that helps users perform logical checks performed when
activities like word processing a user types something into a
or video editing program to ensure that the input
coding—changing information is the expected response
into numbers, letters, or machine code—computer
symbols commands that a processor can
compiler—a program that understand directly; written
translates the source code of only using binary numbers
a high-level language into operator—small function that
executable machine code performs common tasks,
computer programming—the such as adding, subtracting,
process of writing computer comparing, or storing values;
software, which mostly consists often represented by only one
of defining a problem, writing or two symbols
code to solve it, and then programs—written sets of
releasing computer programs instructions for computers that
debugging—analyzing source will help them perform specific
code to locate typos, poor logic, tasks
or improper syntax that creates source code—instructions for a
a glitch in the program computer written in a human-
demotic—cursive form of readable, high-level language
Egyptian hieroglyphs sprites—objects in Scratch that
graphical user interface—the perform the functions
icons and visual indicators that syntax—the order of words in a
allow a user to interact with an phrase, clause, or sentence
operating system or program translators—tools used to
if-then statement—allows a convert the words of one
program to do one thing if a language into another language
Boolean expression evaluates to troubleshooting—investigating
true, or nothing if the Boolean what causes bugs or problems
evaluates to false in programs or computers
infinite loop—a loop that does visual programming
not have an exit condition and languages—coding languages
therefore continues to execute that allows the user to
the same sequence of steps manipulate elements of a
forever program graphically instead of
textually
44
Index
algorithms, 10–11 NASA, 4
BASIC, 31 Obama, President Barack, 4, 16
binary numbers, 12 open source, 13
Boolean expressions, 26–27, 30, Oracle, 15
35 output, 16, 18–19, 24–25
C++, 12, 15 PEMDAS, 9
do-while loop, 36 Pilot, 14
else statement, 32 pseudocode, 16, 36
exit condition, 35–36 Python, 13, 19
graphical user interface (GUI), 6, Rosetta Stone, 18
21, 24–25
Scratch, 17, 19–23, 25, 29, 33, 35,
Hawking, Stephen, 43 37, 39
if-then-else statement, 32 syntax, 12–13, 15, 18, 20
if-then statement, 30–33 variable, 22–23, 27, 29
infinite loop, 34–37 VisualBasic, 19
input, 24–25 Waverly Labs, 14
Java, 15, 19 Windows, 15
machine code, 12–15
Macintosh, 15

45
Check It Out!
Books
DK Publishing. 2014. Help Your Kids with Computer
Coding. DK.
Marji, Majed. 2013. Learn to Program with Scratch: A
Visual Introduction to Programming with Games, Art,
Science, and Math. No Starch Press.
Sande, Warren, and Carter Sande. 2013. Hello World!
Computer Programming for Kids and Other Beginners.
Manning Publications.
Weyn, Suzanne. 2004. The Bar Code Tattoo. Scholastic.
———. 2012. The Bar Code Prophecy. Scholastic.
———. 2016. The Bar Code Rebellion. Scholastic.

Video
Lifelong Kindergarten Group. Getting Started with Scratch.
MIT Media Lab.

Websites
Code.org®. Learn an Hour of Code. https://code.org/learn.
Lifelong Kindergarten Group. Scratch. https://scratch.mit
.edu/.
Lifelong Kindergarten Group. Scratch Wiki. http://wiki
.scratch.mit.edu/wiki/Scratch_Wiki_Home.

46
Try It!
Coding is an integral part of our technological world and
a skill that should be taught to all students. Write a letter to
a leader explaining the benefits of coding education. Before
writing your letter, you have some work to do:
o Decide on your speaking points. Why do you think
coding in schools might benefit the next generation?
Make a list of these points.
o Select three strong arguments to focus on in your letter.
Support your arguments with research. Don’t forget to
include counterpoints and/or perspectives.
o Survey friends and/or kids in your school to see if they
agree. Make sure you can use the information as support
for your letter.
o Write a draft of your letter. Have two classmates edit
and suggest additions or counterpoints to make your
letter stronger. Rewrite a final draft using letter format.
o Research the address of the district, city council, and/or
congressperson who funds education policy in
your area. Mail your letter!

47
About the Author
Rane Anderson lives in Colorado with her
husband and son. She earned a bachelor
of science in geology from California
State University, Long Beach. When she’s
not writing or scaling mountains looking
for cool geologic features, she’s trying to
program her toddler to take long naps, to
never say no, and to eat his vegetables!

Answers
page 9—PEMDAS in Action: Using the order of operations, the
problem breaks down as follows:
(18 + 2 ∙ 3) ⁄ 22
(18 + 6) ⁄ 22
24 ⁄ 22
24 ⁄ 4
=6
page 10—Dig Deeper: 12.56 square feet
page 27—True or False?: False. A true equation could be 7 (x + 2) ≤ 42.
page 38—Find the Error: The error is in the last step. Since
−2 − 7 = −9, the answer should come to 5a2 − 2a − 9.

48
Reader’s Guide

1. Explain why it might be easier to write a program


using a visual programming language than using a
text-based language.
2. Why do computer programmers use high-level
languages instead of machine code to write programs?
3. If you decided to code a program, what kind of
program would you design and what language would
you use?
4. What are some reasons why it’s beneficial for students
to learn computer programming?
Thank you for purchasing this eBook.

This eBook is copyrighted. If you accessed this eBook without making


payment, you should be aware that neither the author nor the publisher has
received any compensation, and you may be in violation of state, federal, and/or
international law.

For further information about our products and services, please e-mail us at:
customerservice@tcmpub.com.

“ Thank you for helping us


create a world in which


children love to learn!

5301 Oceanus Drive Huntington Beach, CA 92649-1030 800.858.7339 FAX 714.230.7070 www.tcmpub.com
Lesson 5: Power of Patterns: Coding

Focus Objectives
Students will be able to:
• use given text features before preparing to read
a text.
• use given text features during reading to increase
comprehension.

Language Objective
• Students will use claims and arguments to write
persuasively.

Word Analysis Comparing Sources


• Etymology: Students will explore the origin • Students will find similarities and
of the word Boolean. differences when looking at two sources
• Breaking Down Words: Students will learn about similar topics.
the four different ways the suffix –an can be • Power of Patterns: Coding (pages 20–25)
interpreted and classify examples of each. and Another Look at Coding student activity
• An –an for Everything student activity sheet sheet (page 11)
(page 7)
Quick Writing Prompt
Comprehension • Students will write persuasive paragraphs
• Model Lesson: Using Text Features: Students using textual support.
will use the acronym T.H.I.E.V.E.S. to use text
features as a pre-reading strategy. Real-World Connections
• Students will present research on a
• Let’s Be THIEVES graphic organizer (page 8)
common computer language.
Close Reading
Opportunities to Develop Fluency
• Close-Reading Lesson: Analytical Filter:
• Students will create computer-specific
Students will find claims, arguments, and
directions on how to accomplish ordinary
cause/effect relationships within a given
tasks.
passage.
• Closer Look: Debugging close-reading
passage (page 9)
• Buggy Causes and Claims close-reading
student activity sheet (page 10)

Teacher Created Materials


5301 Oceanus Drive
Huntington Beach, CA 92649‑1030
http://www.tcmpub.com
TCM 25715 (i13760)
ISBN 978-1-4938-3715-1
© 2017 Teacher Created Materials, Inc.

© Teacher Created Materials 25715 (i13760)—Power of Patterns: Coding 1


Lesson 5: Power of Patterns: Coding (cont.)

Reader’s Guide Reminder


The Reader’s Guide questions in each book encourage students
to think critically and can serve as class discussion starters.
Suggested answers are provided in the Digital Resources.

Word Analysis
1. Etymology—Remind students that • Have students practice creating Boolean
language is something alive and always expressions, and let the class decide if the
changing. New words are created and expressions are true or false. Examples
added to languages when they are needed. to get students started include: 2 + 2 = 5
Understanding where a word came from (false); oceans are saltwater (true); George
and what all its parts are can help us better Washington was the first president of the
know and understand words. United States (true); red and yellow make
green (false). Point out that the questions
• Display the word Boolean for students
cannot be open-ended (“How do you
to see. Tell students this is both a
write a letter?”) or opinions (“Is green a
mathematical and computer science
pretty color?”).
term, and see whether anyone has heard
of it or knows what it means. Let students 2. Breaking Down Words—The suffix –an has
share their thoughts. four generally accepted meanings which
are related, but have some nuances. Explain
• Explain the etymology of the word
the four meanings to the students, and
Boolean to students. The word Boolean
brainstorm examples together.
was coined in 1851 after an English
mathematician named George Boole. • a person belonging to or coming from
The word took his last name, Boole, and (i.e., Asian)
added the suffix –an, which has several
• adhering to or following (i.e., totalitarian)
different meanings, discussed more in
Breaking Down Words. • a person or idea typical of [a certain era]
(i.e., Jeffersonian)
• In math, Boolean refers to abstract
algebraic systems. But as computers came • an expert in (i.e., veterinarian)
into being, its usage slipped into a binary • For further practice, have students
variable. This just means an expression is complete An –an for Everything student
Boolean if it has two possible outcomes— activity sheet (page 7).
true or false.

2 25715 (i13760)—Power of Patterns: Coding © Teacher Created Materials


Lesson 5: Power of Patterns: Coding (cont.)

Model Lesson: Using Text Features


Before Reading
1. Model—Say, “Before reading a nonfiction being familiar with basic programming.
text, it is important to use at least one After discussing, students will fill in the
pre-reading strategy. I know that when I “Title” section on the activity sheet. Have
am reading nonfiction, the text will have students read the introduction (pages
facts, the topic may be unfamiliar, and 4–5) and conclusion (pages 42–43). Have
my purpose is probably to learn new student pairs share their predictions or
information.” thoughts after reading each section.
• Ask students to brainstorm and explain Then, students will fill in their activity
sheets.
some pre-reading strategies they know of
and use. Bring up text features if no one • Bring students back together for a quick
else does, and let the students share what whole-group discussion. Ask questions
they know about that. Using text features such as, Are there any common ideas or
is a bit more of an in-depth pre-reading questions? Do you feel prepared to read the
strategy, but it also gives the reader more book? Do you need clarification?
information and more preparedness for
the text. Model by saying, “It’s clear from reading
theses pages that coding is a remarkable
• Say, “Before you start reading, you tool. I predict that the book will focus on
need to know that you will be ‘stealing’ explaining how coding has been used
information about the book by using the and how it has evolved over the years as
text feature acronym T.H.I.E.V.E.S. Let’s technology advances.”
discuss what each letter stands for and
make sure everyone is familiar with the
topics.” Share each letter of the acronym
with students: T—title; H—headings;
I—introduction; E—every first sentence; English Language Support
V—visuals and vocabulary; E—end of Encourage students to write
chapter questions; S—summary. one question about something
2. Guided and Independent Practice— they do not understand or need
Distribute the Power of Patterns: Coding more information about for each
books and the Let’s Be THIEVES student section of the table. This way, it
activity sheet (page 8). Look at the activity will be easier for you or another
sheet together. Point out that parts of it student to go back over anything
(title, introduction, and summary) can be confusing after the student has
looked at before beginning to read. The finished reading.
other parts can be used before students
begin to read a section.
• Call students’ attention to the front
and back cover. Ask students whether
they have any predictions, questions,
or comments. Statements may range
from “the front cover is confusing,” to

© Teacher Created Materials 25715 (i13760)—Power of Patterns: Coding 3


Lesson 5: Power of Patterns: Coding (cont.)

Model Lesson: Using Text Features (cont.)


During Reading After Reading
1. Model—Say, “When looking at the back 1. Model—After students have finished their
cover yesterday, I noticed some words I activity sheets and have read the entire
wasn’t familiar with—conditional statements book, bring them together as a whole class.
and looping. I have these words flagged Say, “This book had a lot of challenging
in my head, and as I read, I will be on the information in it, but the text features
lookout for their meanings.” helped me recognize what my potential
trouble sections would be.”
• Continue with the T.H.I.E.V.E.S. text
features strategy. Have students turn to • Say, “I found the PEMDAS explanation
page 6. Assure students they do not need helpful because I am already familiar
to write questions and comments on with it, so it helped clarify why coding
their activity sheets for each text feature instructions have to be written in a
for every chapter. specific order.”
• Look through the first two chapters 2. Guided and Independent Practice—Have
(pages 6–19) together, focusing on students work together in small groups
headings. Think out loud as you go of three or four to share any questions
through the pages. Say, “I see we will they wrote on their activity sheets. Have
learn about computer languages with students discuss potential answers as well
translators, and that makes me think of as their general predictions and thoughts
spoken languages!” they wrote down before reading. Were their
predictions true? What was interesting?
2. Guided and Independent Practice—
Have students go through pages 6–19
independently, focusing on reading the first
sentence of each paragraph and looking at
visuals and vocabulary. Let them share their
thoughts with the class and jot down notes
on their activity sheets. English Language Support
• As students finish reading independently, Have students focus on the
remind them to stop at the beginning of headings and visuals, as this
each chapter and choose at least two text will give them an overview of
features to preview before reading. the section without getting
weighed down in the text of every
Assessment Opportunity—As
paragraph’s first sentence.
students are working, make sure
they are varying the text features
they focus on for the chapters. Also,
look for questions they have as they
fill out the T.H.I.E.V.E.S. table on their
activity sheets.

4 25715 (i13760)—Power of Patterns: Coding © Teacher Created Materials


Lesson 5: Power of Patterns: Coding (cont.)

Close-Reading Lesson:
Analytical Filter: Arguments/Claims and Cause/Effect
Introduction
1. Distribute the Closer Look: Debugging close- 7. After marking each sentence with the
reading passage (page 9). necessary notes, students will need to look
back at the passage as a whole, making sure
2. First read: Have students read the excerpt
independently to get the gist of the text. they have at least two causes of computer
After they finish reading independently, ask bugs and two claims about the importance
of debugging.
students to describe the main ideas found
in the passage. • If any students are having a hard time
organizing their notes, it may be helpful
3. Direct students to the filter and focus box
to refer them back to the driving
on the activity sheet. Remind them that
questions and have them point out (and
the purpose of close reading is to read with
label) the parts of the passage which
a specific filter in mind. Good readers use
answer it.
close reading as a way to reread to better
understand the hardest parts of a text. 8. Third read: Have students read the passage
Students will critique the passage, focusing a third time, this time being extremely
on the claims and arguments given and any critical about their notes. Help them study
cause/effect relationships. the notes they marked on their close-
reading activity sheets to discover larger
4. Direct students to the driving questions
trends. Students will record notes about
on the activity sheet and read them aloud:
what they notice in the margins next to the
What can cause problems in code? What
text. After students have completed their
argument is made about the importance of
third reads, ask them to share their answers
debugging? These are the questions that
to the driving questions, using evidence in
they need to keep in mind while rereading
their responses.
the text.
9. Distribute the Buggy Causes and Claims
5. Remind students that they are looking for
student activity sheet (page 10). Using their
some kind of claim and arguments that
annotated passages to help them, they
support it. Students are also looking for
should answer the questions and share
cause-and-effect relationships.
their responses with partners.
Activity
6. Second read: Have students read the
passage again, this time looking for the
arguments about the importance of English Language Support
debugging. These arguments should be Give students the sentence frame
underlined. Sentences or phrases with “Computer bugs can be caused by
cause-and-effect relationships should be _____” to help them clearly identify
marked with a C and E. the potential causes.

© Teacher Created Materials 25715 (i13760)—Power of Patterns: Coding 5


Lesson 5: Power of Patterns: Coding (cont.)

Comparing Sources
Have students read an excerpt from TIME Edge, Another Look at Coding
(page 11), and compare and contrast it to information given in Power of
Patterns: Coding. Discussion should focus on why authors choose one style
of writing over another. For more TIME Edge content, go to timeedge.com to
sign up for a 60-day free trial.

Quick Writing Prompt


Give students time to write responses to the following prompt, changing the
prompt as necessary to fit your actual school district’s technology options:
Imagine your school district wants to decrease its technology budget and get rid
of beginning programming courses. Write a paragraph convincing the district to
stop these budget cuts. Be sure to state your claim, using information from the
text and your own opinion to form your argument.
• Below-grade-level students: Discuss with students both sides of the
issue and write ideas on a chart to help them formulate their arguments.
• On-grade-level students: Encourage students to create pieces that
clearly identify their opinions and give at least two persuasive details
from the text as your support.
• Above-grade-level students: Challenge students to create pieces that
clearly identify their opinions and have at least three arguments from
the text for support. Encourage them to identify any personal opinions
that may add weight to the persuasiveness.

Real-World Connections Opportunities to Develop Fluency


• A few computer languages are mentioned Loops—The text describes loops on pages

in the book, such as C++, Java®, Python®, 34–35. One step to a person may be many
and Visual Basic. Have each small group of smaller steps to a computer. Have groups
students choose one language and conduct of three to four students work together
research to discover more about it—when to create computer-worthy directions to
it was created, what its main uses are, who accomplish small tasks, such as cooking
is likely to use it, etc. Have students create pasta or shooting a free throw. Students will
posters displaying their research. practice reading the directions, focusing on
fluency and expression. It might even be
fun for students to use different intonations
for the computer.

6 25715 (i13760)—Power of Patterns: Coding © Teacher Created Materials


Name: __________________________________________________ Date: _______________________

An –an for Everything


Directions: Sort the words in the Word Bank into the correct meanings of the suffix –an in the table.
Then, choose one word from each column and use it in a sentence.

Word Bank

Christian Elizabethan magician Palestinian

herculean Norwegian republican historian

vegetarian Martian equestrian Victorian

A person or
A person belonging Adhering to or
idea typical An expert in
to or coming from following
[of a certain era]

Sentences
1. ______________________________________________________________________________

______________________________________________________________________________

2. ______________________________________________________________________________

______________________________________________________________________________

3. ______________________________________________________________________________

______________________________________________________________________________

4. ______________________________________________________________________________

______________________________________________________________________________

Etymology Connections
5. Why would a Boolean expression with only a true or false answer be a good fit for a
computer program?

______________________________________________________________________________

______________________________________________________________________________

© Teacher Created Materials 25715 (i13760)—Power of Patterns: Coding 7


Name: __________________________________________________ Date: _______________________

Let’s Be THIEVES
Directions: Use the text features in the table as pre-reading strategies. Make a note of any
predictions, questions, or interesting information in the corresponding spot.

Title

Headings

Introduction

Every first sentence

Visuals and vocabulary

End of chapter questions

Summary

8 25715 (i13760)—Power of Patterns: Coding © Teacher Created Materials


Name: __________________________________________________ Date: _______________________

Closer Look: Debugging


Directions: First, read for the main idea of the text. On the second read, mark any cause-and-effect
relationships with a C or E and underline any arguments for the importance of debugging. Review
and change as needed to find the best evidence to answer the driving questions.

Analytical Filter—Focus on Arguments/Claims and Cause/Effect


Driving Questions: What can cause problems in code? What argument is made about the
importance of debugging?

Margin Notes Debugging Margin Notes


When you finish coding your very first program,
you’ll undoubtedly expect to see the miraculous results
of all the time and effort devoted to the task. So you sit
back and expect to watch your masterpiece at work.
But then…nothing happens. Or maybe something does
happen, but it goes very, very wrong.
This is a familiar story that many coders, professionals
included, could tell, and it’s the reason debugging is
such an important element of computer programming.
Coders will sometimes spend hours trying to determine
why programs don’t run or why there are strange glitches
that are not supposed to exist. Troubleshooting what the
problem is and then how to debug it requires patience
and perseverance.
The General Idea
Unfortunately, there’s no foolproof, step-by-step
method to debug a program. The process of debugging
can be lengthy and often includes a lot of trial and error.
To begin debugging, consider the following questions:
• Are the commands logical?
• Are important commands missing within the code?
• Are any commands out of order?
• Are there commands inside of an if-then statement
that should be outside it or vice versa?

© Teacher Created Materials 25715 (i13760)—Power of Patterns: Coding 9


Name: __________________________________________________ Date: _______________________

Buggy Causes and Claims


Directions: Use your annotated notes from the Debugging passage to answer the questions. Make
sure to include evidence from the text in your responses.

1. What claim is made about debugging?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

2. What arguments are made to support that claim?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

3. What are some of the causes of computer bugs?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

10 25715 (i13760)—Power of Patterns: Coding © Teacher Created Materials


Name: __________________________________________________ Date: _______________________

Another Look at Coding


Directions: Read the following excerpt from TIME Edge, “Play It Smart” by Brian S. McGrath. Compare
it to the information found in Power of Patterns: Coding pages 20–25. Use what you have learned
about Scratch® to help you answer the questions.

All video games, both educational and recreational,


do one key thing: They let players try again. Video
games lower the cost of failure so players will take
risks. We love games because they provide us the
opportunity to fail without consequences, then pick
ourselves up and try again. That’s the key to learning.
Game designers have figured out that well-designed
problem-solving games that give players a second
chance and a way to share their successes are almost
irresistibly attractive. Schools are still trying to figure
out [how to utilize this information].
Game theorist James Paul Gee also says video games
make players think like scientists. Game play is built on
a cycle of “hypothesize, probe the world, get a reaction,
reflect on the results, re-probe to get better results,” a
cycle typical of experimental science.

1. In what ways are the two texts similar?

______________________________________________________________________________

______________________________________________________________________________

2. In what ways are the two texts different?

______________________________________________________________________________

______________________________________________________________________________

3. How do video games and visual programming languages, such as Scratch®, allow users to
improve their skills and ultimately become smarter?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

© Teacher Created Materials 25715 (i13760)—Power of Patterns: Coding 11

Vous aimerez peut-être aussi