c1L10 - Everybody Can Code

Last modified by Daniel Nübling on 2022/08/03 08:12

Everybody Can Code

The goal of this lesson is to show participants that programming is not a mystery and everybody can learn it. With easy analog exercises the basic concepts of programming are introduced, which can later be transferred to an easy online programming interface.  Welcome everybody to the world of code.

Preparation

Exercise "Egg carton Maze"

This exercise shows with a very simple example how computer programs work and is also suitable for kindergarten kids. You can either give participants all the material needed or ask them to gather materials at home and bring them to the class.

Eggcarton Maze

The target of the exercise is to move the toy figure through the egg carton maze in order to catch all the targets. Form groups of 2-3 people. One person is the computer who runs the code and the others are programmers who "write" the code. 

Rules:   

  • The toy figure can't be placed on fields with obstacles.
  • The toy figure can't be moved outside the maze.
  • Only the computer is allowed to touch and move the elements in the maze.

Move commands: To move the toy figure programmers have 3 commands. Draw them as arrows on little snippets of paper:

  • Move one step into the direction the toy figure looks
  • Turn left (without moving forward)
  • Turn right (without moving forward) 

Move Commands

Running the exercise:

  1. The "computer" sets up the maze:
    • Puts the toy figure to the start position (e.g. the lower left space of the egg carton).
    • Places targets on the egg carton.
    • Places obstacles on the egg carton.
  2. The "programmers" start setting up their code by putting together their list of "commands".
  3. Programmers are not allowed to touch and move the toy figure. If they want to do a test run, they need to ask the computer to run the code and see if their commands are right. You might notice that it can be difficult to go through the code in your mind, especially when there are a lot of rotations. This simulates the challenges of real coding. That's why programmers often do test runs with parts of their code to see if this part works or to find errors. Programmers call this process "debugging", as errors in code are referred to as "bugs".  

Code example: In order to move the toy figure to the (yellow) target, programmers need to perform a minimum of 6 commands: forward, move left, forward, forward, move left, forward.

Code example

Variations of the exercise: By limiting the number of command snippets you force participants to optimize their code. This can also mean that they might not reach all targets. This simulates real conditions of coding where time and resources are often scarce.

With this exercise participants learn the basic principles of coding:

  • A program or code is a set of commands a computer executes one after the other.
  • If a programmer makes a mistake the code does not work. The computer is not able to fix it on his own.
  • Programmers optimize their code for a minimum set of commands. This speeds up the code execution and reduces the potential of errors. 

Participants might notice that the code will become very long if you have to put one snippet for each step. That brings them to the next level of coding: bundling commands. Instead of putting 4 forward commands in a row you can also use the command  "execute [x] times" to make the code easier. To introduce these commands there is very good instruction and templates at: https://researchparent.com/coding-a-lego-maze/. If participants already have some knowledge about coding you can also do this exercise instead of the egg carton version:

Coding a Building Block Maze

Exercise: Scratch Programming

In this exercise participants will create a first easy program in an online programming tool called "Scratch".  Two participants use one PC together, as people usually feel more confident trying out new things when they don't do it on their own.

Start the PCs and open a web browser and open the page https://scratch.mit.edu In the main menu select "Create" to start the Scratch tool:

Scratch Programming Tool

Learn the elements of the tool with a first easy program:

  • The code tab on the left side shows a list of categories. If you click on a category all available elements of this category are listed in the second column as colored elements. 
  • In the middle of the screen there is a central area where you can drag the elements with your mouse.
  • In the upper right corner you see the output window with the cat. This is where your program is running.   

Let's start setting up an easy program:

  1. On the code tab on the left side click on "Events".
  2. Select the first element "when [green Flag] clicked" with your mouse...
  3. and drag it to the central area of the screen.
  4. On the code tab on the left side click on "Motion", select the element "move 10 steps" with your mouse and place it below the yellow element. You see how the blue element snaps to the yellow one when you move it next to it. Increase the number of steps to 20.
  5. Click on the green flag above the output window. This starts your program and the cat moves 20 steps to the right. 

Move Cat in Scratch

Let's get to something a bit more complex. We'll let the cat ask for your name and welcome you. Try to build the program as shown in the following image. To easily find the elements they have the same color as the category. E.g. you will find the purple element "say Hello! for 2 seconds" in the purple category "Looks".

Scratch Program

If you struggle getting the "answer" element into the last line of the code, go back to the "Sensing" section where you found the "ask What's your name" and wait" element. Right below this element is the "answer" element that you can drag to the purple element. This is an example where a program stores information in a placeholder, a so-called "variable".  

Scratch variable

That's most of the magic behind programming. In order to write more sophisticated programs you need to learn all the elements and commands of a programming language but you can call yourself now a programmer. In case participants found their passion for programming there is a lot of very good tutorials for scratch: https://scratch.mit.edu/ideas. The good thing about scratch is that it works in basically any browser without installing anything or registering. 

Method / Process description

References

Short facts

Target groupAdults or children
SettingGroup work and plenum
Time2 units à 45 min.
Material
  • Square egg cartons
  • Toy figures 
  • Objects that serve as obstacles (we used beechnut hulls as they look spikey)
  • Objects that serve as targets (use sweets if you want to increase motivation...)
  • Internet-enabled PC
Tags: