Introduction to Programming: Module 1 Blockly (Lois Delcambre)
Part 1 – blockly
What is a program? A step-by-step set of instructions
an program – for a person allrecipes.com Just flash this long enough for people to realize that this is a recipe
A program for a pianist Same thing – just flash it http://www.elikamahony.com/2013/04/04/awakening-and-enchantment-piano-sheet-music-available/
Same thing – just flash it http://www.architecturendesign.net/18-clear-succinct-ways-to-wear-a-tie/
You need to know how to do the task, step by step, before you can write a program to perform that task! Imagine trying to write the instructions for tying a Windsor knot – if you don’t know how to do it.
Plan Blockly a programming language used at code.org - to teach beginners how to program Python a programming language used by Google and other companies. Also used for teaching. We’ll use the turtle module
Plan for today introduction to puzzles; blocks executed one after the other; repeat block (with blocks inside) blocks that check conditions repeat while, if, if/else defining new blocks/commands by defining functions
a puzzle You need to write a program so that the bee can: get all the nectar (from flowers) & make all the honey (in honeycombs) I think you can go very quickly through the next dozen slides or so.
the bee
dark green squares - where the bee can move
The rest of the puzzle board can be ignored. 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 forward (one square) turn left/right get nectar from a flower make honey in a honeycomb
One program that works …
Another program that works …
A program that doesn’t work … Why not?
Screen layout – for blockly
the puzzle
the description of the puzzle
the commands/blocks you can use
your program
drag and click commands to attach them to other commands
Pull them apart to rearrange your commands (note this program has an error)
Pull them apart again
drag and click in a new block
fill in how many times you want to repeat
drag and click command(s) into repeat block
push this button to run your program
Demo at code.org Go to the code.org website Click on “Elementary School” under “Educators” – the blue box second from the left Click on “Curriculum Overview” Click on Course 3
go to Course 3
Course 3, Lesson 13, Puzzle 1: bee nested loops
Course 3, Lesson 13, Puzzle 1: bee nested loops Modify/complete this program to solve the puzzle
More Class Activity Write two different programs for each Course 3, Lesson 13, Puzzle 2 (skip the video) Course 3, Lesson 13, Puzzle 3 Also … try to make mistakes, run the puzzle before you complete it, move outside of the dark green area, try to make honey, etc. I can imagine that you won’t do this for the teacher workshop.
Plan for today introduction to puzzles; blocks executed one after the other; repeat block (with blocks inside) blocks that check conditions repeat while, if, if/else defining new blocks/commands by defining functions
take the Zombie to the sunflower; avoid the chomper 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 Note: in blockly, specific conditions (for the puzzle you’re working on) are built-in.
The beginnings of a program Course 3, Lesson 8, Puzzle 3
A completed program that works
Maze (zombie); Course 3, Lesson 8, Puzzle 4 everyone try it
Class Activity to practice conditionals Course 3: Lesson 8, Puzzle 1, 2, 3, and 8 if/else and repeat until with the zombie
Plan for today introduction to puzzles; blocks executed one after the other; repeat block (with blocks inside) blocks that check conditions repeat while, if, if/else defining new blocks/commands by defining functions
Defining new commands!!! video Make sure this link works. It should be a video of Chris Bosh explaining how you can “define new commands” in blockly by defining functions. He makes some great basketball analogies. I want to show this to the teachers because this (to me) is probably one of the most important parts of the CS curriculum. Students need to know that through the use of functions they can make their code: more readable, more reusable, much more easy to debug/develop, and so on. So , it would be god for teachers to see this. Video is short – maybe a minute or two. I linked to the youtube version of this video; there’s a copy on the code.org site; I can find it for you if you like.
Note: we’ve seen functions before This next part could be skipped – but you can also flash through it.
http://kids.niehs.nih.gov/games/songs/childrens/baa_baa_black_sheepmp3.htm Chorus: Baa, baa black sheep, Have you any wool? Yes sir, yes sir, Three bags full. One for the master. One for the dame. And one for the little boy who lives down the lane. Chorus One to mend the jerseys, One to mend the socks. And one to mend the holes In the little girl's socks.
http://kids.niehs.nih.gov/games/songs/childrens/baa_baa_black_sheepmp3.htm function definition Chorus: Baa, baa black sheep, Have you any wool? Yes sir, yes sir, Three bags full. One for the master. One for the dame. And one for the little boy who lives down the lane. Chorus One to mend the jerseys, One to mend the socks. And one to mend the holes In the little girl's socks. function name function invocation
Note: we are expected to sing the chorus http://kids.niehs.nih.gov/games/songs/childrens/baa_baa_black_sheepmp3.htm function definition Chorus: Baa, baa black sheep, Have you any wool? Yes sir, yes sir, Three bags full. One for the master. One for the dame. And one for the little boy who lives down the lane. Chorus One to mend the jerseys, One to mend the socks. And one to mend the holes In the little girl's socks. Note: we are expected to sing the chorus in the beginning, once. In a program, the function definition is NOT executed. It is only executed when we have a function invocation. function name 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 Triple Coconut Cake Recipe More ingredients More instructions
Let’s see functions in blockly The next dozen or so slides just explain how function definition appears in blockly. Teachers should get the idea of what this is – maybe by discussing it with their neighbor. They may or may not want to try using it in blockly.
This gray box defines a function; you can put code in the gray box
Here is the name of the function
the new function is just like any other command!
“get 5” command is in the program (note: this program doesn’t work)
Class Activity to practice using functions Course 3, Lesson 6: Puzzles 3, 4, and 5 Show this to teachers but don’t expect them to do it. (or, don’t even show it.)
For practice repeat, repeat until, if, and functions Course 3: Lesson 13 – all puzzles Course 3: Lesson 8 – all puzzles Course 3: Lesson 6 – all puzzles This doesn’t really need to be in here – but it can be; just don’t spend any time here. I may change it for 2017.