Monday, May 6, 2013

Scratch Programming: Lesson 4

Using Variables and Sub-Routines

Review:
Who changed their random number guessing program to include a count of how many guesses were used to get the right answer?

What other changes did you make to your program?

Intro:
Teacher flips a coing while student guesses the answer.
Steps:
1. Ask, "what do you pick? Heads or Tails?
2. Flip the coin
3. Check the answer

Instruct:
There are three steps required to guess coin flips.  However those major 3-steps are broken down to sub-routines.  In this lesson we will learn how to make the best use of sub-routines.  When we used Light-Bot in our first lesson we used functions to give instructions to the robot.

In this lesson you will create one main program:

When green flag is clicked
Forever loop
When broadcast ___ wait
When broadcast ___ wait
When broadcast ___ wait

Set the broadcast to:
get player choice
flip coin
compare result



Then create sub-routines for each type of broadcast.

When I receive get player choice

You must use the "and wait" command so the computer knows to wait until all sub-routines are completed.  Also ALWAYS use a stop script command.


Sub-routine
When I receive flip a coin
set coin flip to pick random 1 to 2
use an if-else command to assign the numbers to either heads or tails


When I receive compare results sub-routine
Use an if-else command so the program can decide if the answer was correct.



 Finished program is below:



Extension Activity:
Make a new game.  This time the game is Rock, Paper, Scissors.  The program will be same as above but instead of only 2 random answers (heads or tails) there is a possibility of 3 random answers.

No comments:

Post a Comment