Very simple programming, limited exposure to assignment and variables minutes, or a full lesson with extension exercises

Similar documents
Synthesis Paper CEP 416 Erica Lewis. variations of innovations within technology. Each technology has both strengths and

Error Detection and Parity Lesson Plan

HTML/CSS Lesson Plans

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

In this lesson you will learn: How to capture the input from the user. How to write programs using variables and lists. Athletics Swimming Gymnastics

Overview: Students explore how they can use to communicate with real people within their schools, families, and communities.

Making a maze with Scratch

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical

Sending LESSON PLAN UNIT 1. Essential Question How do you connect with others through ? Lesson Overview. Learning Objectives

Teaching London Computing

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

Lesson 2 / Overview. Large Group Introduction

Sending LESSON PLAN UNIT 1. Essential Question How do you connect with others through ?

Using the Olympus WS-110 Digi-Recorder. Part A - Setting it Up. Introduction. A1. Inserting the Battery. A2. Turning On and Off

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Welcome to Computers for ESL Students, 4th Edition

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #13. Loops: Do - While

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Sending LESSON PLAN UNIT 1. Essential Question How do you connect with others through ?

Valuable points from Lesson 6 Adobe Flash CS5 Professional Classroom in a Book

Teacher Cheat Sheet - Game Coding Challenges

Materials Computer skill: cover the basics of the computer, its hardware and its software Computer skill: learners will set up an address

Bring in several pieces of junk mail that have been opened and spread the mail around the classroom.

TEACHERS NOTES AND SOLUTIONS

Intro. Scheme Basics. scm> 5 5. scm>

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CSC 258 lab notes, Fall 2003

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Lesson Share TEACHER'S NOTES LESSON SHARE. ing by Olya Sergeeva. Overview. Preparation. Procedure

Example Candidate Responses. Cambridge International AS & A Level Computer Science. Paper 2

2D Shapes, Scaling, and Tessellations

VBA Foundations, Part 12

Problem Set 1 Due: 11:59pm Wednesday, February 7

The Environment. Scratch Programming. The Environment. The Environment. The Environment. The Environment. Lesson 1: Introduction THE STAGE

UNIVERSITY OF CAMBRIDGE INTERNATIONAL EXAMINATIONS. Cambridge ICT Starters On Track

Math Day 2 Programming: How to make computers do math for you

15 Minute Traffic Formula. Contents HOW TO GET MORE TRAFFIC IN 15 MINUTES WITH SEO... 3

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

What you can do: Use Transparency #10

Printing Envelopes in Microsoft Word

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

roboturtle Documentation

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java

Introduction to Programming with Python. By: Victoria Kahian and Kyla Boswell

Lesson Plan. Course Title: Principles of Information Technology Session Title: Intro to Databases Lesson Duration: Varies dependent upon instructor

CS Final Exam Review Suggestions - Spring 2014

(Refer Slide Time 01:41 min)

Finding and Fixing Bugs

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

DCS/100: Procedural Programming

7. Arrays, More Java Looping

Your First Windows Form

Learning Objectives. Description. Your AU Expert(s) Trent Earley Behlen Mfg. Co. Shane Wemhoff Behlen Mfg. Co.

XP: Backup Your Important Files for Safety

Introduction to Programming with JES

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras

Teaching London Computing

Computer Basics: Step-by-Step Guide (Session 2)

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Lecture 2: Variables & Assignments

One of these "compartments" is more correctly referred to as an element of the array

NS6-50 Dividing Whole Numbers by Unit Fractions Pages 16 17

Programmable Control. Name Class Teacher. Ellon Academy Technical Faculty

code-it.co.uk Exploring Regular 2D Shapes & Patterns using sequence, repetition, nested loops, Program Aim: Program regular 2D shapes

Using external Media such as CD's and Pen Drives. Reading from a CD and writing to a pen drive Contributers: Aruna Prabahala Std: III Grade Level

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Lesson 1 Python: Interactive Fiction

ISY00245 Principles of Programming. Module 7

February 11, Nintendo. Bob Rost January 14, 2004

DCS/100: Procedural Programming


Subtracting with Multi-Digit Numbers Adaptable for 2 nd, 3 rd, 4 th, and 5 th grades*

Integers and Rational Numbers

(Refer Slide Time: 00:01:30)

CS4023 Week04 Lab Exercise

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

Geometry Sixth Grade

Unit 4 Reasoning about shape. Year 4. Five daily lessons. Autumn term. Unit Objectives. Link Objectives

QUIZ. What is wrong with this code that uses default arguments?

Using GitHub to Share with SparkFun a

CS 177 Recitation. Week 1 Intro to Java

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

Chapter 1. Data types. Data types. In this chapter you will: learn about data types. learn about tuples, lists and dictionaries

Stratford School Academy Schemes of Work

The WideRuled Story Generator Tutorial Alex Mitchell Communications and New Media Programme National University of Singapore

i wonder, therefore i am. Welcome to the Wonder League! This packet includes everything you need to know about Dash, Dot, and how to get started!

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

Preview from Notesale.co.uk Page 3 of 79

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Name: Magpie Chatbot Lab: Student Guide. Introduction

PowerPoint Basics: Create a Photo Slide Show

edofe Management Toolkit

GAP CLOSING. Grade 9. Facilitator s Guide

Teacher Guide. Edline -Teachers Guide Modified by Brevard Public Schools Revised 6/3/08

PRESENTING INFORMATION LEVEL 1

Transcription:

Box Variables Age group: Abilities assumed: Time: Size of group: Focus Variables Assignment Sequencing Programming 10 adult Very simple programming, limited exposure to assignment and variables 15-20 minutes, or a full lesson with extension exercises 3 upwards Syllabus Links This activity is appropriate for any syllabus aim about learning to program that requires an understanding of variables and assignment. Summary You dry run simple programs that involve variables and assignment by running them on a computer made of students. Students with boxes act as variables as values are copied between them following the instructions of the program. You physically demonstrate the creation of variables, how accessing a variable involves taking a copy of its value, and how storing values in a variable destroys any previous value stored. Technical Terms Assignment, Variable, Value, Declaration, Initialisation, Sequencing. Materials 3 A4 Boxes (e.g. lids of photocopy paper boxes) Variable Name Labels Print off the sheets, laminate hole punch, tie with string or ribbon Value cards Print on to paper the colour of the text. The program Program slides for relevant language, write programs up on board, or give out as a handout Computer Science activities with a sense of fun: Box Variables V1.0 (24 February 2014) Created by Paul Curzon, Queen Mary, University of London for Teaching London Computing: http://teachinglondoncomputing.org

What to do The Grab: Explain that understanding variables and assignment is critical to being able to program but is an easy thing to be confused about. Get over this hurdle and programming will be far easier. A good way to think of variables is that they are like special boxes with their own private shredder and photocopier built in - boxes that can store but also create and destroy. The activity: Display the fist program. It swaps the values stored in the variables. Explain that you are going to demonstrate how the program works, and in particular what and how variables and assignment work. It is helpful if the class to have seen a simple use of variables prior to this activity e.g., just to store a value input that is immediately printed. The following is a general introduction if not. One of the most important things that computers do is process data. They store values numbers, text, images, sounds manipulate them, do calculations with them, make changes to them and store the results until they are needed. For example, music editing software might be used to record samples of sounds, edit them, combine them with others, store the results and then play the final version. A texting or tweeting program stores the words you type, allowing you to edit them until you are ready to send the message. Programming languages therefore need a way for programmers to write commands that tell the computer to store data and to move it around. The first thing needed are a way to refer to places that store data. Programmers call these variables. As a program is likely to have lots of variables you need a way of knowing which one is which so variables are given names. The names are used to indicate the particular one the program should use at any point. Before variables can be used you need to create them. In some languages (eg Python) they are created automatically the first time they are mentioned. In others like Scratch you have to tell the system to create them. In yet others (like Java) you have to explicitly create them using special instructions in the language itself. These instructions are called declarations. [Explain just the situation in the language you are teaching. We will use Python syntax in the following explanation: substitute the appropriate language]. When you create a variable, you are first of all picking a place in memory to store data. Point to the first instruction in the program. colour1 = red This creates a new variable called colour1 and stores the string red in it. Emphasise that it is best to pronounce the equals symbol as gets the value as in colour1 gets the value red. Let s demonstrate what that means in practice Computer Science activities with a sense of fun: Box Variables V1.0 (24 February 2014) Created by Paul Curzon, Queen Mary, University of London for Teaching London Computing: http://teachinglondoncomputing.org

Pick a student from the audience and give them a box to hold. Point out that you have just created a new variable a storage space. A variable is just like a box that can hold a single thing. As your program will be creating more variables, you need a way to tell which one is which. You need to give them a name. Take the name label for colour1 and get them to put it round their neck. Point out that any previous name (eg the one their mother gave them!) is now forgotten. From now on they will be called colour1. Explain that in writing the program you could have made up any name for them as long as you use that name consistently through the program to refer to that variable, that storage box. The rest of the command is an assignment. It just stores a value in a variable. It puts something in the box. First (on the left hand side of an = sign) you give the name of the variable i.e., the place to store the value. On the right hand side you give the value to be stored there. Here the value to be stored is the string red. colour1 = red So this assignment puts value red into the variable called colour1. Get one of the value cards with red written on it and put it in the box called colour1 following the instruction. Move to the next command: colour2 = green This is very similar. As one doesn t already exist, it creates a new variable called colour2. It then stores value green in it. Get another volunteer, give them a box and name label, and put a value card with green on it in their box. Storing something in a variable (putting something in a box) for the first time is called initialising the variable. In the above the assignments initialised colour1 with the value red and colour2 with the value green. Emphasise the difference between values and names of variables. Values are the things that can be stored in boxes the cards. Names are just labels (hung round the necks of volunteers). In the programming language string values have quotes round them so you know they are values not names of variables. If there are no quotes then it will either be a keyword or the name of a variable. We have initialised our two variables with starting values. Now we can do something with the data we have stored there. In our simple little program, we will just swap the two values over, so that at the end, colour1 holds green and colour2 holds red. The next instruction is temp = colour1 We haven t seen temp before so we need to declare the variable. Pull out a third volunteer and give them a box and the temp label. This assignment is a little different to the previous two though. The right hand side is the name of a variable (no quotes round it) not a value. That means first get a copy of what is in that variable, i.e., what is in colour1, and put the copy in the variable called temp. Go to the person representing colour1, making a show of checking their name. Ask them what is in their box. Create a copy of it, either by getting a blank card and writing the value out or getting a ready-made card. Put that copy in to the box labelled temp. Emphasise that colour1 has not changed at all it still has its original value which was not touched. The variable temp now just holds a copy of it. Emphasise also Computer Science activities with a sense of fun: Box Variables V1.0 (24 February 2014) Created by Paul Curzon, Queen Mary, University of London for Teaching London Computing: http://teachinglondoncomputing.org

that the assignment was temp gets a copy of the value in colour1 not the other way round i.e., the movement is in the direction temp colour1 The next assignment is similar. colour1 = colour2 We have finished creating variables though the variables referred to here are both ones we previously created. This assignment just makes a copy of the value in colour2 and places it in colour1. Go to the person acting as colour2 and find out what value they are storing. Make a copy. Again something new is happening. We are not just doing an initialisation. We are storing a value in a variable that already has a value. It is important to emphasise that a variable can only store one value. When you put a new value in a box, you destroy the old one. As you put the new value in colour1, make a show of taking out the old one and destroying it screw it up, tear it up, eat it, jump up and down on it something that theatrically destroys it. Point out that that value is now gone forever and the new value stored is the one just copied from the other variable. The final assignment is similar, this time copying the value from temp into colour2 whose value is destroyed: colour2 gets the value in temp. colour2 = temp Act this out in a similar way to the previous one. Point out that the value in temp was the one saved from colour1 in the earlier step. That means even though the value in colour1 was destroyed, because a copy was stored safely first, we end up with the same value in colour2. Finally look at the results. What has happened? The values in colour1 and colour2 have been swapped over using temp as extra storage space. Originally colour1 was red and colour2 green. Now colour1 is green and colour2 red. Finish by re-emphasising that variables are like special storage boxes and in particular: - variables are given names so they can be referred to again, - variables hold values: the actual data that is being stored, - it is important not to confuse the names of variables with their values, - a variable can only store one value at a time, - when you get a value from a variable you are making a copy, that variable s value is untouched, and - when you store a new value in a variable you destroy anything that was previously there. Refer back to the boxes as you cover these points. Give the class a chance to ask questions about what happened while the volunteers are still out the front, and use the props to explain any misunderstanding. Computer Science activities with a sense of fun: Box Variables V1.0 (24 February 2014) Created by Paul Curzon, Queen Mary, University of London for Teaching London Computing: http://teachinglondoncomputing.org

Variations and Extensions Faulty swap Repeat the dry run process using a faulty swap program (see below) that doesn t use an extra temporary variable. colour1 = red colour2 = green colour1 = colour2 colour2 = colour1 See if the class can predict in advance what will happen. Get them to call out what should be done at each step and at the end get them to try to explain what has happened and why. Assignment Dry Run We strongly recommend doing the Assignment Dry run exercises soon after this demonstration to reinforce the understanding and also quickly correct any mistaken mental models students might hold. Other programs Demonstrate what is happening using boxes as variables in a series of other short programs including answers to simple programming exercises the students have attempted. Types Demonstrate types in a similar way, using, for example, small boxes for integers and bigger boxes for strings. This is best kept as a separate follow-on activity rather than explaining it at the same time as variables and assignment. The key thing students struggle with a correct mental model of, and need to understand first, is the way variables and assignment work in general. Arrays Arrays can be demonstrated as boxes with compartments with the whole box named and each compartment numbered. Staple a series of boxes together to make one. Further Reading Computing without computers A free booklet by Paul Curzon on programming, data structures and algorithms explained using links to everyday concepts. Available from http://teachinglondoncomputing.org/resources/ Computer Science activities with a sense of fun: Box Variables V1.0 (24 February 2014) Created by Paul Curzon, Queen Mary, University of London for Teaching London Computing: http://teachinglondoncomputing.org

Links to other activities Assignment Dry Run Dry run on paper a series of short fragments of code involving assignment. This is an important activity to do after explaining variables and assignment. It reinforces understanding and helps identify faulty mental models so they can be fixed. It is a pencil and paper exercise executing code. Being able to do this kind of dry run for any new construct is an important prerequisite to being able to actually write code. The swap puzzle Solve a puzzle, coming up with an algorithm that your team can follow faster than anyone else. This gives a way to introduce the idea of the solution to a problem being a set of instructions that allow others to solve it with no understanding. It also explores how different algorithms can solve the same problem but may not be equally good some may be faster. The intelligent piece of paper Take part in a test of intelligence against an intelligent piece of paper! This is a good introduction to what an algorithms is and how a computer program is just an algorithm. It can also be used to start a discussion on what it would mean for a computer to be intelligent. It can lead on to an unplugged programming activity creating winning instructions. The Invisible Palming Trick Teach a trick where the magician invisibly moves a card between 2 piles. This is a fun way to introduce the idea of an algorithm, showing how algorithms are a series of steps that if followed precisely lead to something (in this case magical) being guaranteed to happen even if the person (or computer) following the algorithm doesn t know what they are doing. Live demonstration of this activity Teaching London Computing give live sessions for teachers demonstrating this and our other activities. See http://teachinglondoncomputing.org/ for details. Videos of some activities are also available or in preparation. Computer Science activities with a sense of fun: Box Variables V1.0 (24 February 2014) Created by Paul Curzon, Queen Mary, University of London for Teaching London Computing: http://teachinglondoncomputing.org

Name card colour1

Name card colour2

Name card temp

Value card Red

Value card Red

Value card Red

Value card Red

Value card Green

Value card Green

Value card Green

Value card Green

Scratch: What does this program fragment do? SET colour1 TO red SET colour2 TO green SET temp TO colour1 SET colour1 TO colour2 SET colour2 TO temp

Scratch: What does this program fragment do? SET colour1 TO red SET colour2 TO green SET colour1 TO colour2 SET colour2 TO colour1

Python: What does this program fragment do? colour1 = red colour2 = green temp = colour1 colour1 = colour2 colour2 = temp

Python: What does this program fragment do? colour1 = red colour2 = green colour1 = colour2 colour2 = colour1

Java: What does this program fragment do? String colour1 = red ; String colour2 = green ; temp = colour1; colour1 = colour2; colour2 = temp;

Java: What does this program fragment do? String colour1 = red ; String colour2 = green ; colour1 = colour2; colour2 = colour1;