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 that 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.
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:
- A BMI of 18.5 or less is considered underweight.
- A BMI between 18.5 to 24.9 is considered healthy.
- A BMI between 25-29.9 is considered overweight.
- A BMI of 30 or over is considered obese.
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 button below to make the computer execute these steps. The output from this program will be displayed to the right of the program.
Press the button below to bring up an “Audio Tour” that explains this program, line-by-line.
Change the value of the height
variable in the program from 60
to
52
. Press the Run
button again and notice the change in output.
Change the value of the weight
variable from 110
to 95
and run the
program again. Finally, change the value of bmi_metric
from bmi * 703
to bmi * 73
.
This last change is an error. You can press the and use the slider to step back through the changes you made to the original version of the program.
-
csp-1-3-1: Imagine that you are 5 foot 7 inches and weighed 140 pounds. What will this
program print for your BMI?
- 21.9
- Close, but the computer will give you more digits than that.
- 21.92470483403876
- 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.