Problem solving and first programs · 4 / 5

Scratch: your first program

Today you will read and order blocks on paper, then make a cat move, speak, and draw a square in Scratch.

builders 120 min

Scratch: your first program

Today you will read and order blocks on paper, then make a cat move, speak, and draw a square in Scratch.

Teacher block: Ocen the robot

Akello plays a game with Ocen. Ocen is the robot. She gives him one instruction at a time. He must do exactly that.

“Move 10 steps,” says Akello. Ocen walks 10 steps.

“Turn right,” she says. He turns a quarter turn.

“Move 10 steps. Turn right. Move 10 steps. Turn right. Move 10 steps.” Ocen has walked four sides. He is back where he began.

Ocen says: This is boring to say. Can you say it in a shorter way?

How would you say all that in fewer words?

Teacher block: Recall from yesterday and last week

Think. Then show with your fingers.

  1. What is 00110 as an ordinary number? 1. 5 2. 6 3. 7
  2. How many bits are in a byte? 1. 4 2. 8 3. 16
  3. In a flowchart, a loop is an arrow that: 1. goes back to an earlier box 2. leaves the End 3. starts at the Start
  4. Which of the four steps asks “does my answer make sense?” 1. Understand 2. Look back 3. Plan

Teacher block: What a program is, and the parts of Scratch

A program is a set of instructions for a computer, written in a language the computer can follow. Last week you wrote algorithms in English. A program is an algorithm written so that a machine can run it.

Scratch is a language where you build programs by snapping blocks together, like Lego. It was made at MIT in the United States and first came out in 2007. Young people all over the world use it. We use Scratch 3.

The parts:

Directions: 90 is right. 0 is up. 180 is down. minus 90 is left.

Teacher block: Sequence, repeat, and predict

Blocks run from top to bottom. That is sequence. We write scripts on paper as text. The lines inside a repeat are written further to the right.

Script A

when green flag clicked
say Hello! for 2 seconds
move 50 steps
say I am here for 2 seconds

Script B

when green flag clicked
repeat 4
    move 10 steps
    say Hi for 1 seconds

The lines further to the right are inside the repeat. They run four times.

Predict first. Script A: what does the cat say first? Where does it end if it starts at x 0, y 0? Script B: how many times does it say Hi? How many steps does it move?

Say your guesses for Script A and Script B first. Then open the answers.

Think first. Say your guess to your partner. Then press the button.

A repeat is a loop: the same blocks, again and again. For the square, two blocks go round four times:

12
  1. move 100 steps
  2. turn right 90 degrees

Teacher block: Put the blocks in order

In pairs. You have strips of paper, each with one block. They are mixed. Put them in the right order. Move the strips about until the program works.

Problem 1. The cat says Hello for 2 seconds. Then it walks 100 steps, three times. Then it says Done for 2 seconds.

move 100 steps
say Done! for 2 seconds
when green flag clicked
repeat 3
say Hello! for 2 seconds

Problem 2. Draw a square with the pen. One block does not belong.

repeat 4
pen down
turn right 90 degrees
when green flag clicked
forever
move 100 steps

Write the right order on your sheet.

Teacher block: Wonder, the loom that read cards

In France, in the early 1800s, Joseph Marie Jacquard made a loom, a machine for weaving cloth, that followed instructions on cards. Each card had holes punched in it. The holes told the loom which threads to lift for one row of the cloth.

The cards were tied together in a long chain, in order. Change the cards, and the same loom weaves a new pattern. Years later, Charles Babbage planned to give instructions to his calculating machine on punched cards too.

If one card in the chain is in the wrong place, what happens to the cloth?

Teacher block: Paper exercise and check

Read the blocksName:

Name:

1. The cat starts at x 0, y 0, facing right.

when green flag clicked
go to x: 0 y: 0
repeat 3
    move 50 steps

Where is the cat on the x line?

2. Look at Script B from the board (repeat 4: move 10 steps, say Hi for 1 seconds). How many times does the cat say Hi?

How many steps does it move in all?

3. The square: repeat 4: move 100 steps, turn right 90 degrees. How many steps does the cat walk in all?

4. Put the lines of Problem 1 in order. Write the letters. A is move 100 steps. B is say Done. C is when green flag clicked. D is repeat 3. E is say Hello. Write the order from the top. A goes inside the repeat.

5. Put the lines of Problem 2 in order. F is repeat 4. G is pen down. H is turn right 90 degrees. I is when green flag clicked. J is move 100 steps. K is forever. Write the letters in order, leaving out the one that does not belong.

6. Change the square to a triangle. How many sides will you repeat? How many degrees must the cat turn each time?

CheckQuestion 1 of 4

What starts a script when you click the green flag?

Laptop block: Task card, my first program

With no teacher. Read the card. Follow it. Ask your partner first.

Your pair: one driver and one navigator. Swap every 10 minutes. If there are 3 of you, one is the timekeeper and joins a pair as a second navigator. Rule: do not change another person’s file.

Before you start: if the Lenovo is off, switch it on. Open Scratch. Windows: Start, type Scratch, press Enter. Mac: Command and Space, type Scratch, press Return. It needs no internet. Wait for the cat to appear.

Look at the screen. On the left, the block palette with the coloured groups. In the middle, the code area, where you build. On the top right, the stage with the cat. Under the stage, the sprite pane, where the cat is called Sprite1.

Part 1: Use (10 minutes). Build this.

  1. Click Events (yellow). Drag when green flag clicked into the code area.
  2. Click Looks (purple). Drag say Hello! for 2 seconds under it. It snaps on.
  3. Click Motion (blue). Drag move 10 steps under the say block. Change the 10 to 100.
  4. Click Looks again. Drag another say Hello! for 2 seconds to the bottom. Change the words to I walked!
  5. Predict first: what will the cat do? Then click the green flag above the stage.
  6. Click the green flag again. What changed? Where did the cat start this time? Fix it: drag go to x: y: from Motion and put it right under the hat block. Its numbers show where the cat is now, so click each number and type 0. Click the flag twice again.
  7. Save: File, then Save to your computer. Choose your week2 folder inside projects. Name it cat-walks. The file ends in .sb3.

Swap!

Part 2: Modify (10 minutes). Change your program, one thing at a time. Predict before each run. Write each change and what happened on paper.

  1. Change the 100 to 50. Predict, then run.
  2. Click Control (orange). Drag repeat 10 and drop it right above the move block. The repeat wraps around the move block and every block below it. Drag the last say I walked! block out of the repeat and snap it under the repeat, so only move is inside. Change the 10 to 3. Predict where the cat ends. (3 times 50 is 150. The x and y numbers show in the sprite pane, under the stage.) Run.
  3. Add a wait 1 seconds block inside the repeat, under move. Run. What changed? Is it faster or slower?
  4. Add next costume from Looks inside the repeat. Run. What do you see? (The cat’s legs change as it walks.)

Swap!

Part 3: Create (15 minutes). Draw a square.

  1. Click File, then New. If it asks about saving, choose not to save, because your first one is already saved.
  2. Click the blue button in the bottom left corner, Add Extension. Choose Pen. A green group called Pen appears.
  3. Build this script:
when green flag clicked
erase all
go to x: 0 y: 0
point in direction 90
pen down
repeat 4
    move 100 steps
    turn right 90 degrees
pen up

The erase all, pen down and pen up blocks are in Pen. point in direction 90 is in Motion. 4. Predict: what shape? Where does the cat finish? Then click the flag. 5. Click the flag again. Why does the square not change? (Erase all wipes the old one, and the cat starts from the same place each time.) 6. Change the 100 to 60. Predict, then run. 7. Save as scratch-square in your week2 folder.

Swap! If there is time, the other learner changes the repeat to 5 and the turn to 72, and checks that 5 times 72 is 360.

Stuck? Before you ask anyone, try three things:

  1. Read the step again, slowly, out loud.
  2. Ask your partner: “What do you see? What did we change last?”
  3. Look at the paper Parsons problems from the teacher block. Check the order and what is inside the repeat. If it still fails, write the problem on paper and carry on.

Laptop block: Challenges

Choose one level. Save each new project in your week2 folder.

Warm up, everyone (3 minutes). Put the blocks of Problem 1 in order on the page. The block marked “inside the repeat” goes inside the repeat above it. (No laptop? Use the paper strips from the teacher block.)

Problem 1: say Hello, walk three times, say Done

Put the steps in the right order. Use the arrow buttons, or drag a step.

    Bronze

    Use set pen color to and set pen size to (in Pen) to change how your square looks. Run it three times with different numbers. Write what each number does.

    Silver

    Draw a triangle: repeat 3, move 100 steps, turn right 120 degrees. Predict first. Save as scratch-triangle. Then write why 120 works. (3 times 120 is 360.)

    Gold

    Draw a hexagon (6 sides) and work out the turn yourself. Then type your rule in a text file named my-rule.txt in week2: “For a shape with this many sides, the turn is 360 divided by the number of sides.” Test the rule with 5 sides (72 degrees) and 8 sides (45 degrees).

    Say it out loud: my program

    Stand up and talk for one minute.

    Tell us what your program does, block by block. What was one change you made, what did you predict, and what happened?

    Use this shape: My program starts when … . Then … . I changed … to … . I thought … would happen. It … .

    Exit question

    Show with your fingers.

    A script says: repeat 5, move 20 steps. How many steps does the cat move in all?

    1. 25
    2. 100
    3. 20

    Then say one sentence: “Today I learned that …”

    Tick your skills.

    Home mission

    Paper (everyone). Write a Scratch script on paper, using the block lines, for this story: the cat says Hello, then walks to the market in 4 steps of 25, then says “We are here!” Use a repeat. Draw the flowchart for it as well. Show someone at home and ask them to trace it.

    Phone (only if a family phone is free, and you have asked). Find one event on the phone (something you touch that starts an action) and one loop (something that repeats until you stop it, such as a ringing alarm). Write them down.

    I can...

    Pick your name first, at the top of the page.

    ← How computers count: binaryBuild and Show: a moving story →

    Use the arrow keys