C3.1 Solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves sequential, concurrent, repeating, and nested events.
Activity 1: Repetitive Events Related to Daily Life
- Begin a mathematical discussion with students related to repeated events by showing them an illustration like the one shown below:
![The 4 cards of the ace of a deck of cards.](/img/activite/algebre/en/4e/VE4_Algebre_Image168_en.png)
- Ask students the following question: What happens in this pattern?
Possible answers:
ABAB pattern for the number attribute ("ace, two" is repeated).
Suite ABCD for the symbol attribute ("hearts, diamonds, spades, clubs" is repeated).
AABB pattern for the colour attribute ("red, red, black, black" is repeated).
- Ask students questions to help them understand that there is more than one structure. This prepares them to explore the nested structure of the loop within the loop.
- Then ask students the following question: How could you extend the following?
- Form small, heterogeneous groups, including students who have observed the pattern in different ways. Invite students to discuss with other group members. Listen to their reasoning.
- Ask students to create a pseudo code for a robot that must deal cards according to a pattern.
Example of Pseudocode
When the code is executed :
Repeat (number of repetitions) times
Repeat (2 times)
Place an ace
Place a two
Change colour
This example of pseudocode will give a pattern of the type "ace black, two black, ace red, two red", and this, for the number of repetitions of the pattern defined by the first loop.
Students can then repeat the activity by creating a pattern using cards and asking a partner to create the pseudo code for the robot that will extend the pattern.
Activity 2: Financial Literacy and Nested Events
A fourth-grade student does extra household chores for her parents to earn spending money. Her parents pay her an amount per hour of work, which she receives on Friday of each week. She decides to save the money earned.
Using nested events, create code that will predict the value of one's savings after a certain amount of time.
This situation is open-ended "by design" to encourage students to use variables in creating their code.
Sample Code
Code | Result (output) |
---|---|
![]() |
For the following entries: Money given per hour worked = $10 Number of hours worked per week = 5 hours Savings period = 1 year or 52 weeks (The duration of the saving is a constant in this code, the number of repetitions in the outer loop) ![]() |
Using a nested loop allows the student to see the multiplicative effect of the loop within the loop. The operation represented here would effectively be 52 weeks × (5 hours per week × $10 per hour) or
52 × (5 × 10). This code is limited because the hours worked remain constant from week to week. An extension of this activity could be to add elements to the code to make it more adaptable. The student, for example, could enter his or her hours in a list, and the code could take the average of the entries to make predictions.
Sample Code
Code | Result (Output) |
---|---|
![]() |
For the following entries: Money given per hour worked = $10 Number of weeks worked = 4 Hours worked per week = 2, 4, 3, 4 Savings period = 1 year or 52 weeks ![]() |
Note: The section of the code that resets all variables to zero, at each run, has been omitted from the example to simplify it. This pattern, which should be at the very beginning of the code, would look like this:
![](/img/activite/algebre/en/4e/VE4_Algebre_Image160_en.png)