Course VVBasic B - Lesson 1

Overview

This lesson introduces or re-introduces the class to computer science, programming, and VVBasic. Even if the class followed a CSEd module in a previous year, some students will be new, and most will only remember bits and pieces, so this lesson starts from the beginning.

The VVBasic commands introduced in this lesson are PRINT, CLEAR, and NUMBER.

Introductory

Warm up the class with some questions they will enjoy answering.

What do you remember from last year? (if appropriate)
Who has a computer at home?
What are the parts of a computer? (monitor, keyboard, mouse, modem, printer, scanner, speakers, disk drives, CPUs, etc.)
Which parts of the computer are for input, and which for output?
What VVBasic commands do you remember?

Tell the students that when they go to the web page, they will see two windows. One window is for entering commands, and the "output window" is where the results of some commands are displayed. Introduce the PRINT command by writing several examples on the board and asking students what the computer will output. It's worth mentioning that VVBasic's PRINT does not involve the printer, or ink, or paper.

PRINT command Output Points to make
PRINT 7 7 Numbers are printed as-is, in the output window.
PRINT 6+3 9 The computer does the math.
PRINT  6  +  3 9 The computer doesn't care about spaces before or after +, -, *, and /.
PRINT "Hello" Hello Text has to be in quotation marks.
PRINT "Hello" " Goodbye" Hello Goodbye The computer can print more than one item.
PRINT "Hello" "Goodbye" HelloGoodbye If you want a space in text, you have to put it in yourself.
PRINT "6+3" 6+3 If numbers or math is in quotation marks, the computer does not do the math. Digits in quotation marks are just digits, not numbers.
PRINT "6 + 3 = " 6+3 6 + 3 = 9 The computer prints the "6 + 3" in quotation marks exactly as-is, and computes the value of the 6 + 3 not in quotation marks. This example is important, confusing, and worth repeating in several variations.

The introduction to variables starts with numeric variables which are assigned a value when they are created. Ask students if they have seen variables in math class. In VVBasic commands such as PRINT, numeric variables act just like numbers, as these examples you write on the board make clear:

VVBasic commands Output Points to make
NUMBER X = 15
PRINT X
15 A numeric variable has to be defined with NUMBER before it is used. When a variable is printed, its value is shown (not its name).
NUMBER X = 15
PRINT X * 2
30 Variables can be used just like numbers. Asterisk is used for multiplication, and forward slash for division.
NUMBER MealsPerWeek = 21
PRINT "Meals per day: "
      MealsPerWeek / 7
3 We try to use more meaningful variable names than "X". Variable names can't have spaces in them; they can just be made of letters and digits (but no digit at the front).
NUMBER Age = 11
PRINT "Age " Age
Age 11 Note that Age is only treated as a variable if it isn't in quotation marks.

Programming Lab

The first step in all labs is to log on to the computer, start a web browser, and go to http://vvbasic.csed.org. If students work in pairs, two to a computer, they should take turns at the keyboard after every step. It's often best to have the regular teacher decide which students should sit next to each other, or partner with each other. Commentary for the teacher follows some lab steps in italics.
  1. Enter this program in the program window:
    PRINT "I like"
    PRINT "computers"
    
    and press the Run button. You should see some text in the output window.
    Some students will use two apostrophes instead of a quotation mark (and that won't work).

  2. Delete the quotation mark (the ") from the end of the first line, and run the program again. You should see an error message. Do you understand what it means? Put the quotation mark back and run the program again (it should work now).
    A critical programming skill is learning to read and understand error messages.

  3. Change the PRINT statements so the program says something a bit more interesting. Put a CLEAR statement at the start of the program. Run your program.
    Some students can spend hours making the computer print "Computers are stupid" or "Sammy likes Sally." They are flexing their mental muscles.

  4. Press the Clear button, and then enter this program in the program window:
    PRINT 1 + 2 * 3 - 4 / 5 + 6 * 7
    
    and press the Run button. You should see a number in the output window. Put parentheses around 3 and 4 like this (3 - 4) and run the program again. Did the output change? Why?
    The students should, of course, see a change due to order of operations. Some students type = instead of + and the program outputs False. (For instance, PRINT 3 + 4 = 5 is valid and prints False.)

  5. Experiment with PRINT statements using some other mathematical expressions. Try adding, subtracting, multiplying, and dividing big numbers (maybe 8764657868), small numbers (0.000001), and negative numbers (-123). What happens if you tell the computer to divide by zero?
    Some students, usually boys, love to type in as big numbers as they can (or dare!). You might ask students doing this step how they would check if the computer is printing the correct answer.

  6. Press the Clear button, and then enter this program in the program window (use your name instead of Abner):
    CLEAR
    NUMBER DollarsPerHour = 6.50
    NUMBER HoursPerWeek = 12
    TEXT Name = "Abner"
    PRINT Name " works " HoursPerWeek " hours a week."
    PRINT Name " earns " DollarsPerHour " dollars an hour."
    PRINT "In one week " Name " will earn "
       HoursPerWeek * DollarsPerHour " dollars!"
    
    Press the Run button. Change the value of DollarsPerHour or HoursPerWeek (or both) so that you earn $100 or just a bit more.
    We're sneaking in the TEXT command here, to be formally introduced next week. Students usually find out the difference between the CLEAR command and the Clear button through experimentation. This step asks the students to experiment with different values to find a desired result.

  7. You probably know that one meter is 39.37 inches. Write a program with a variable called Height . The value of this variable is your height in inches. The program should print out your height in meters.
    The students' programs should look something like this:
       NUMBER Height = 46
       PRINT "My height in meters is " Height / 39.37
    Some students don't know their height. Students often multiply by 39.37 instead of dividing. One student who had recently moved to the U.S. from Germany only knew his height in centimeters!

Concluding Questions and Answers

Ask students to tell you how to write a program that will print
  34 * 9 + 6 = 312
where the computer does the arithmetic. They should tell you something like PRINT "34 * 9 + 6 = " 34 * 9 + 6.

Evaluation Activity

Write a few PRINT statements on the board that are variations of those from the lecture, and have the students "play computer" and determine what the output will be.

Thoughts

An important pair of concepts in this and later lessons are "input" and "output." Many components of a physical computer are directly associated with input or output (or both), as are several VVBasic commands.

Many teachers find that it is not useful to make a clear distinction between "the computer" and "VVBasic" and "the web page" and "the applet" etc. For instance: "When the computer sees PRINT 3+4, it knows it should do the arithmetic, and the output is 7."