Introduction to Programming Module 1 Blockly Lois Delcambre
Introduction to Programming: Module 1 Blockly (Lois Delcambre)
PART 1 – BLOCKLY
What is a program? • A step-by-step set of instructions 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! Imagine trying to write the instructions for tying a Windsor knot – if you don’t know how to do it.
Plan 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/else 3. 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)
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.
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/else 3. defining new blocks/commands by defining functions
take the Zombie to the sunflower; avoid the chomper Could you write the program? sunflower 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 1. introduction to puzzles; blocks executed one after the other; repeat block (with blocks inside) 2. blocks that check conditions repeat while, 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/children s/baa_black_sheepmp 3. 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. Chorus
http: //kids. niehs. nih. gov/games/songs/children s/baa_black_sheepmp 3. 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. function definition function name Chorus One to mend the jerseys, One to mend the socks. And one to mend the holes In the little girl's socks. Chorus function invocation
http: //kids. niehs. nih. gov/games/songs/children s/baa_black_sheepmp 3. htm 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. 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. function definition function name Chorus One to mend the jerseys, One to mend the socks. And one to mend the holes In the little girl's socks. Chorus 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
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
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
- Slides: 59