Compute with Numbers

We won’t be using lots of math in this eBook, so don’t worry if math isn’t your favorite thing. You will run and modify programs that work with words, turtles (virtual ones), and images as well as numbers. The only math that you need to know is addition, subtraction, multiplication, and division.

Computers were first used for calculations. You may be used to doing calculations with a calculator, but calculations are often easier if you can name the numbers you are working with. When you name a number, or the result of a calculation, you are creating a variable. A variable is a name associated with computer memory that can hold a value and that value can change or vary. One example of a variable is the score in a game. The score starts off at 0 and increases as you play the game.

A game in Scratch with a score

Figure 2: A pong game in Scratch with a score shown in the upper left.

One thing that you might want to calculate is a Body Mass Index. Body Mass Index (BMI) is a measure of body fat that is useful in screening for health issues. Generally speaking:

To calculate a BMI, you need the height in inches and the weight in pounds. You square the height (multiply the height in inches by itself), then divide the weight in pounds by the squared-height. BMI is defined in terms of meters and kilograms, so to convert from pounds and inches multiply by 703.

In the box below is a computer program that calculates and prints the BMI for someone 60 inches tall (5 feet) and 110 pounds.

Press the run button button below to make the computer execute these steps. The output from this program will be displayed to the right of the program.

Pres the audio tour button button below to bring up an “Audio Tour” that explains this program, line-by-line.

You can only use the Save and Load buttons if you are logged in. The Save button will save the current program and the Load button will load a saved program.

Change the weight (in inches) and height (in pounds) in the program above, and press the Run button to calculate a new BMI.

    csp-1-3-1: Imagine that you are 5 foot 7 inches and weighed 140 pounds. What is your BMI?
  • 21.9
  • Close, but the computer will give you more digits than that.
  • 21.924704834
  • Yes!
  • 21
  • No, the result will be a number with a decimal point and numbers after the decimal point.
  • 22
  • No, the computer does not round the result.


Discuss topics in this section with classmates.

Show Comments
Next Section - Compute with Words