C3. Coding:
Solve problems and create computational representations of mathematical situations using coding concepts and skills.
Learning Situation: Shoe Sizes
Total Duration: approximately 180 minutes
Overview
In this learning situation, the student collects the shoe sizes of the students in their class in order to suggest an inventory of shoes for preteens at the community shoe store. From the data, the student creates code using a block coding program in order to find the mean and the median of the shoe sizes of the students in the class. The student observes that adding or subtracting data can affect measures of central tendency
Overall Expectations | Specific Expectations |
---|---|
D1. Data Literacy Manage, analyse, and use data to make convincing arguments and informed decisions, in various contexts drawn from real life. |
D1.5 Determine the impact of adding or removing data from a data set on a measure of central tendency, and describe how these changes alter the shape and distribution of the data. |
C3. Coding Solve problems and create computational representations of mathematical situations using coding concepts and skills. |
C3.1 Solve problems and create computational representations of mathematical situations by writing and executing efficient code, including code that involves events influenced by a defined count and/or subprogram and other control structures. C3.2 Read and alter existing code, including code that involves events influenced by a defined count and/or subprogram and other control structures, and describe how changes to the code affect the outcomes and the efficiency of the code. |
High-Impact Instructional Practices in Mathematics | Description |
---|---|
Direct Instruction | During Warm-Up, activate students' prior knowledge to mode, the median and the mean. Introduce new
terminology such as measures of central tendency and subprogram. Show a subprogram
(pseudocode for mode) and asks students about its pseudocode. Have students think and reflect then share with
a partner. Next, have students write pseudocodes for the median and mean. |
Small-Group Instruction | As students are writing their code, provide small-group instruction, about 10 minutes at a time, with predetermined groups. Support students in developing their understanding around conditional statements and how these statements can affect the code. |
Flexible Groupings | Communication and collaboration are assets in tasks like this. Encourage students to collaborate in teams, either by mixing diverse skill sets for peer teaching or by grouping them based on similar abilities for personalized instruction. |
Prior Knowledge and Skills
To be able to carry out this learning situation, the student must:
- understand what pseudocode is;
- know the measures of central tendency;
- be able to use a block-based programming language.
At the end of this learning situation, the student will be able to:
- determine measures of central tendency using block-based program;
- write efficient blocks of code that uses conditional statements as well as operator commands;
- describe the effect that adding or removing certain data values can have on the measures of central tendency.
Achievement Chart Criteria
Skills | Criteria |
---|---|
Knowledge and Understanding |
|
Thinking |
|
Communication |
|
Application |
|
* Custom Blocks: This screenshot shows the menu for creating a new block in the Scratch coding program. By creating a new block, one can make the code more efficient by summarizing a sequence of code to be repeated at various places in the code into a single block. Creating blocks in other block coding program might have an interface that differs from this one.
Materials
- block-based program
- paper
- pencil
Note: The examples in this learning situation were created using Scratch.
Mathematical Vocabulary
measures of central tendency, mode, median, mean, subprogram, pseudocode
Before Learning (Warm-Up)
Duration: approximately 15 minutes
Assessment can be carried out through…Ask the students, as a class, to observe the picture below while trying to imagine the mathematical problem that could be associated with it.
Show students the picture below. Inform them that the two pictures are related. Ask them again to ask questions and try to determine the problem associated with the picture. Guide questioning so that students ask questions about measures of central tendency (mean, median, and mode).
Sample questions:
- What do the numbers in bold mean?
- What mathematics is related to shoes?
- Are all the shoes in the picture the same or different? How does this affect your interpretation of the problem?
Possible Observations | Possible Interventions |
---|---|
The student does not discuss measures of central tendency. |
What does the formula represent? Have you ever used a formula like this? In what context? Why do you think the number 2 is written in bold? |
The student has no idea what the shoes might represent. |
How many shoes do you see? What do you think are the shoe sizes? How can shoes differ from each other? |
The student does not know the measures of central tendency. | Review with students the concepts of mode, median and mean. |
Active Learning (Exploration)
Duration: approximately 150 minutes
Assessment can be carried out through…Getting Ready for Coding
Explain to the students that the data concerning the shoe sizes of the students in the class needs to be collected. Using this data, students are to write code to determine the mean and median of shoe sizes using a block-based program.
Discussion Questions and Sample Responses
- What data about the shoes do we need to collect?
We need the shoe sizes of the students in the class. - How can the data collection be automated?
Using a code (in blocks or in a spreadsheet), visiting a website where you can create surveys, filling out a form, etc. - Is it possible to write a code for the data collection? What will the code need to do?
The code should ask for a student's shoe size, store that shoe size in a list, then ask another student until all the data is
collected (a pseudocode could help with this step). - Is it easier to write code to determine the mean, median or mode?
- Some student may say that the median or the mode are easier to code because it is simply a matter of finding a number in a list, while the mean requires a mathematical operation. In reality, the code to sort the list of data in ascending order is much more demanding than the code to do mathematical operations. It would be interesting and relevant to ask this question again at the time of consolidation.
- What does the code need to do to calculate or recognize each of the measures of central tendency?
- For the mean, the code has to calculate the sum of all the data, then divide this sum by the number of data
values in the
list. - For the median, the code has to sort the data in ascending order and recognize the central value, either by
finding
the value in the center of the list (odd number of data) or by calculating the mean of the two values in the center of
the list (even number of data). - For the mode, the code needs to total the number of shoes sizes and determine which has the greatest total.
- For the mean, the code has to calculate the sum of all the data, then divide this sum by the number of data
values in the
As a class, present the pseudocode below to help students understand what a pseudocode is.
Variables: nb1 |
nb2 |
sum |
Begin |
Set nb1 = 0. |
Set nb2 = 0. |
Set sum = 0. |
Define the value of nb1. |
Ask the question "What is the value of nb1?. |
The answer becomes the value of nb1. |
Define the value of nb2. |
Ask the question "What is the value of nb2?. |
The answer becomes the value of nb2. |
Sum = nb1 + nb2 |
End |
- What are the variables? What do they represent?
The variables are:- nb1: the value of the first datum collected;
- nb2: the value of the second datum collected;
- sum: the sum of all data.
- What is the purpose of the three "set to 0" blocks at the beginning of the code?
Without the "set to 0" blocks, all the variables that were set during the last execution of the code will remain active. This could have undesirable outcomes from the code. It is like pressing the "CE" key on a calculator. - What would be the code, in a block-based program, for this pseudocode?
Invite students to transfer the pseudocode into code for a block-based program.
Sample code
Note: In this part of the learning situation, the students individualize their blocks of code by the questions they ask and the variables they use. If the students have prior experience in using the coding program, it is possible for them to go directly to the next part o fthe activity, which is data collection. This activity can also be used as a diagnostic assessment to determine if students have everything they need to move on to data collection.
Take the time to circulate among the students and listen to their conversations. Based on their observations and your active listening, question them, if necessary, to guide them or better understand their reasoning.
Coding to collect data
Ask the students to create a pseudocode to collect data from all the students in the class. Students can start from the code prepared in the previous step or start a new code.
Example of pseudocode:
Variables:
_ number of data to enter
_ shoe size
_ shoe size data list
Begin |
Repeat for each data. |
Ask for shoe size. |
Add the answer to the list of shoe sizes. |
Ask if there is any data left to enter. If yes - repeat If not – end |
Once the pseudocode is complete, invite students to create their code to collect data related to the size of students' shoes and then compile it into a list.
Sample code
Note: Several block-based coding programs make block customization options. If so, students can create a block (custom block) and define it with their code. This way, the main code becomes less cluttered.
Example of a custom block
Once this block is created, the main code would look like this:
Coding to Analyze Data
Ask students what the computer will need to do to find the average shoe size from the data collected. If necessary, the starting image with the formula for the mean could be redisplayed to activate students' prior knowledge. The mean formula can also be transformed into pseudocode. Invite them to write the instructions for the computer to calculate the mean of the data collected.
Here is an example of pseudocode:
Variables:
_ list number (or list element)
_ sum
_ list of shoe sizes
Begin |
Set list number to 1 (we start with the first element of the list). |
Set sum to 0. |
Repeat for the length of the list (number of elements). |
Add (element 1) from the sum list. |
Add 1 to number in the list. |
Say mean = sum/length of list. |
End |
Sample code
Ask students the following questions:
- What happens if I add more shoe sizes to my list?
- Will the mean stay the same? Why?
- Can this code be made more efficient?
This code is structured in this way in order to separate the steps and to encourage student questioning and exploration. A simpler version of this code would see the list items appended to the value of the "sum" variable at data collection time, eliminating that whole step. This code would look like this:
Invite students to write pseudocode and code to find the median shoe size of the students in the class.
Possible questions
- What steps are needed to determine the median?
- Is there a block that can cause the data to be ordered in ascending order? Can we create one? (Students may mention that the elements of the list of shoe sizes must be sorted in ascending order in order to find the median.)
Example of pseudocode:
Variables:
_ central value 1
_ central value 2
\* list of shoe sizes
Begin |
Put "shoe size list" in ascending order. |
If the list has an even number of elements |
Identify the element corresponding to (length of the list /2). |
Set the value of the element to ("central value 1"). |
Identify the element corresponding to ((length of the list /2) + 1). |
Set the value of the element to ("central value 2"). |
Set median to (("central value 1" + "central value 2") /2). |
OR |
Set median to the element corresponding to ((list length + 1) /2). |
End |
Note: If the list contains an even number of data values, highlight to students that the median is the average of the two middle numbers.
Here is a sample of code that places the list of data into an ascending order. Again, the code has been turned into a custom block. This step is helpful, but not necessary.
Short explanation of the logic of the code
This code works by comparing a value in the list with the surrounding value. If the value is smaller, the positions of the elements in the list are reversed. The code is repeated the same number of times as there are elements in the list to ensure that each value is smaller than the next.
Ordering numbers in ascending order is a complex problem for the computer, which must compare the data values and then order them. This kind of problem lends itself very well to an Internet search. There are several communities and a range of existing projects that can answer questions from students and staff. By modelling this kind of resourcefulness, students become more comfortable doing the same, and learn more about what is possible with block-based coding programs.
Sample code to find the median
Ask students the following questions: What happens if I add shoe sizes to my list? Will the median stay the same? Why?
Possible Observations | Possible Interventions |
---|---|
The student is unable to enter all the sizes of the students' shoes in a list. |
In which block can you ask a question? What question can you ask here? What variables do you need? |
The student does not reset the variables to zero. |
What happens when your variables are not reset at the beginning of the code to zero? What is the effect on data entry in the list? Ask the student to return to see the pseudocode that was analyzed beforehand. This pseudocode also contains “set to 0” blocks. Encourage them to find the connection between these blocks in the two codes. |
Student does not use variables appropriately. |
Ask the student what the variables mean. Understanding the meaning of the variables used is necessary for understanding the code. The student may not understand the names of the variables. Encourage them to rename their variables with terms that are familiar in the context of the problem. |
The student has challenges with writing new blocks (custom blocks) of code. |
Which block category can help you create new blocks? Ask the student why we create new blocks (to make the codes more efficient by being shorter or to make the code easier to analyze or debug by isolating certain sequences from the main code). |
The student has challenges with writing code to calculate the mean. |
Ask the student to review their pseudocode for the mean. Encourage them to locate the calculation of the mean in their pseudocode, then identify the corresponding blocks in their code. If there are blocks missing, that would be the first step. Review with the student the meaning of the blocks and variables. Are the right variables in the right places in the formula? If necessary, ensure that the values of the variables are displayed on the screen. In this way, the student has a visual cue of the values and is more likely to be able to detect if there is an error. |
The student has challenges with writing code that orders the data values in ascending order. |
Ordering data in ascending order using blocks may require logic. Ask the student what it takes to order a list in ascending order (for example, determine if each value is smaller than the next). How would one get the computer to understand this? Show the student the operators "greater than" and "less than" as a clue. Invite the student to search the Internet to see if this problem already has a solution instead of creating all new code. |
The student has challenges with writing code that finds the median. |
Ask the student the meaning of some of the operator blocks. What does the conditional statement block IF, THEN, THEN mean? How do you usually find the median of numbers? In this code, what variables are needed to find the median? |
Consolidation
Duration: approximately 15 minutes
Assessment can be carried out through…Have students exchange their pseudocode with another classmate and have them read each other's pseudocode. Have students provide each other feedback and ask questions. Next, have students exchange their code for a block-based program and have them compare the pseudocode with it. Have student provide further feedback and an opportunity to ask more questions. After discussion, have students adjust their codes, as necessary.
Reflection Questions
- What did you notice about your partner's code?
- How did your partner's code compare to yours?
- What alterations would you like to make to your codes? What suggestions did you offer your partner about heir codes?
In order to continue learning about coding, continue practicing switching from a pseudocode to a code, or from a code to a pseudocode.
Ask students if there are other ways to code to analyze data (for example, spreadsheet, such as Sheets and MS Excel).
Ask students to explain the advantage of writing code related to measures of central tendency using block-based coding program, instead of using =Average and =Mean commands in a spreadsheet. (Block-based coding gives us an opportunity to see what happens behind the scenes when we use shortcuts in a spreadsheet. Creating this code allows us to explore the power of conditional blocks (IF, THEN, UNLESS) and loops (repeat, repeat until).
Extension
Provide students with an activity in which a table of values can be generated using a defined count, that is, a loop in which a list of values is generated according to term number and term value.
Some examples of activities that use the "repeat until… " block:
- Write code that will collect an exact number of data (for example, repeat until the number of responses = 10) to facilitate the calculation of some measures of central tendency. Here, the number could also correspond to the number of students in the class so that each student is allowed only one response.
- Write code that collects data until a maximum sum is reached (for example, repeat until sum of values = 250). This kind of code could be useful for cumulative entry of points to hit a target. It would then be possible to use the measures of central tendency to determine the mean or the median of points for each entry.
Links to Other Curriculum Expectations
Number
B2.1 Use the properties and order of operations, and the relationships between operations, to solve problems involving whole numbers, decimal numbers, fractions, ratios, rates, and percents, including those requiring multiple steps or multiple operations.
By using conditional statements (if, then, else), it would be possible to write code that can analyze a mathematical problem and determine the processes to be followed to solve it by using subprograms (for example, subprograms for the priorities of operations, for the addition of fractions).
Algebra
C4. Apply the process of mathematical modelling to represent, analyse, make predictions, and provide insight into real-life situations.
Using subprograms and custom blocks allows you to generalize a situation by creating models and calling on those models at various points in the code.
Data
D1.5 Determine the impact of adding or removing data from a data set on a measure of central tendency, and describe how these changes alter the shape and distribution of the data.
By creating a subprogram for each measure of central tendency, it would be possible to write code that calls each subprogram at different times, creating more efficient and easy to read/alter code.
Instructional Differentiation and Universal Design for Learning
- Suggest to the student who is looking to take up a challenge that they write a code to find the mode of the
students' shoe
sizes. This code will use the list of data sorted in ascending order, but the conditions to be determined will be very different. - By using a coding program where project sharing is possible, some of the code could already be in place so that
students do
not always start from a blank canvas. - Work at the pace of the students. Transferring mathematical knowledge and concepts to coding can take time.
Allocate the
necessary time to each part of the learning situation. - Provide students with pseudocodes so they can turn them into codes. The pseudocode can also have a color code
that
guides the student to the correct category of blocks in the chosen coding program. - Provide a cheat sheet on the function of some more complex blocks, such as operators and conditions.