2.b.4. modeling with code
- Use the Computer Coding handout (PDF) to record your answers to question 3, or use your notebook.
- Use the Computer Coding Practice handout (PDF) to record your answers to question 4, or use your notebook.
[Note: The coding apps below are quick first drafts. We are in the process of redesigning them.]
1. BUILDING GROWING PATTERNS WITH CODE
Complete the following in your notebook, or use the Coding Practice - Growing Patterns handout.
a. Let's take a close look at the pattern below.
Notice that two things are happening as the pattern grows from stage 1 to stage 4.
- the blue blocks increase by 3 - we have 3, 6, 9, 16
- the red blocks stay the same - we have 3, 3, 3, 3
Here is how we can create this pattern with computer code. Use the yellow buttons to change the code and see the effect.
b. Explore the Growing Patterns app below, which builds bar graphs of growing patterns you have explored.
Predict the outcome when the yellow buttons are clicked.
Plan how you to change the code to have the following effect.
- make the bar graph steeper
- make the bar graph less steep
- make the bar graph taller
- make the bar graph shorter
- make all bars the same height
Use the app to test your ideas and then answer the following.
- What colour makes the graph steeper of less steep?
- Is it the blue or the red blocks? Or is it both?
2. MORE ABOUT CODING
a. The app below show how computer code can be used to print the word "math" a number of times. Click on the yellow buttons to explore.
This code uses what is called a For/Next loop.
for x = 1 to 5
For/Next loops are used in computer coding for repetitive tasks.
b. Let's compare the two apps below. Click on the yellow button to explore.
Notice that the first app prints the same number over and over, while the second app prints a growing pattern of numbers. Can you see what part of the computer code makes the difference?
c. Explore For/Next loops in the app below. (Note: * means multiply)
3. CODING IN BASIC
Write your own computer code, using the BASIC computer language:
- Go to www.compileonline.com/execute_basic_online.php (or use this link to open it in a new window), where you will see the screen below, after you click on Execute Script. (here is another option for BASIC programming)
- the screen on the left is for the computer code
- the screen on the right is for the output
Add three more lines to the code screen, as shown below.
PRINT "Hello World"
for x = 1 to 10
Click on Execute Script to see the output. It should look like this:
Change line 4 to read as follows. The symbol "*" means "multiply".
Predict what the output will be. Click on Execute Script to check your answer. It should be a list of the first 10 even numbers and it should look like this:
Try different options for the expression in line 4, such as:
a. What will the following programming code print?
for x = 1 to 8
b. What will the following programming code print?
for counter = 1 to 5
c. What will the following programming code print?
for p = 1 to 10
print p + 1
d. What will the following programming code print?
for x = 10 to 20
e. What will the following programming code print?
for d = 1 to 10
print d, 2*d
f. Write the programming code that would do each of the following:
- print the phrase "I love math" 20 times
- print the numbers 1 to 100
- print the numbers 5 to 15
- print the even numbers 4 to 20