Escolar Documentos
Profissional Documentos
Cultura Documentos
Blockly
(Lois Delcambre)
PART 1 – BLOCKLY
What is a program?
3
an program – for a person
allrecipes.com
4
A program for a pianist
http://www.elikamahony.com/2013/04/04/awakening-and-enchantment-piano-sheet-music-available/ 5
http://www.architecturendesign.net/18-clear-succinct-ways-to-wear-a-tie/ 6
You need to know how to do the task, step
by step, before you can write a program to
perform that task!
1. Blockly
a programming language used at code.org - to teach
beginners how to program
2. Python
a programming language used by Google and other
companies. Also used for teaching. We’ll use the
turtle module
Plan for today
1. introduction to puzzles;
blocks executed one after the other;
repeat block (with blocks inside)
2. blocks that check conditions
repeat while, if, if/else
3. defining new blocks/commands by defining
functions
a puzzle
The bee
can’t
go there.
a flower
where a bee can
get nectar
small number
tells you how
many times
the bee can sip
nectar here
a honeycomb
where a bee can
make honey
small number
tells you how
many times
the bee can deposit
honey here
bee blocks/commands
1. introduction to puzzles;
blocks executed one after the other;
repeat block (with blocks inside)
2. blocks that check conditions
repeat while, if, if/else
3. defining new blocks/commands by defining
functions
take the Zombie
to the
sunflower;
avoid the chomper
sunflower
Could you
write the
program?
zombie
chomper
Some commands can check conditions
• A condition returns
either True or False
• A condition can be
checked each time a
repeat until block is
about to run
• A condition is checked
once for an if command
• everyone try it
Class Activity to practice conditionals
1. introduction to puzzles;
blocks executed one after the other;
repeat block (with blocks inside)
2. blocks that check conditions
repeat while, if, if/else
3. defining new blocks/commands by defining
functions
Defining new commands!!!
• video
Note: we’ve seen functions before
http://kids.niehs.nih.gov/games/songs/childr
ens/baa_baa_black_sheepmp3
.htm
Chorus:
Baa, baa black sheep,
Have you any wool?
Yes sir, yes sir,
Three bags full.
Chorus
Chorus
http://kids.niehs.nih.gov/games/songs/childr
ens/baa_baa_black_sheepmp3
.htm
Chorus: function
Baa, baa black sheep, definition
Have you any wool?
Yes sir, yes sir,
Three bags full.
function
One for the master.
name
One for the dame.
And one for the little boy
who lives down the lane.
Chorus
Chorus
http://kids.niehs.nih.gov/games/songs/childr
ens/baa_baa_black_sheepmp3
.htm
Chorus: function
Baa, baa black sheep, definition
Have you any wool?
Yes sir, yes sir,
Three bags full.
function
Note: we are expected name
One for the master.
to sing the chorus One for the dame.
And one for the little boy
in the beginning, once. who lives down the lane.
function
function definition is One to mend the jerseys,
One to mend the socks. invocation
NOT executed. It is only And one to mend the holes
In the little girl's socks.
a function invocation.
Another Example of Function Definition
and Invocation (on next page)
Triple Coconut Cake Recipe
http://www.seriouseats.com/recipes/2017/06/coconut-cake-recipe.html
This recipe asks you to make
other recipes (defined elsewhere)
Triple Coconut Cake Recipe
More ingredients More instructions
Function Invocation