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 block-based programming software 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
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. Algebra
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.

Preferred High-Impact Instructional Practices in Mathematics Description
Direct Instruction During Warm-Up, the teacher questions the students about the mode, the median and the mean in order to activate their prior knowledge. In light of student responses, vocabulary under study is introduced such as measures of central tendency and subprogram. The teacher shows a subprogram (pseudocode for mode) and asks students about the pseudocode. Students voice their opinions/reflections in a think-pair-share and then work in guided practice to create pseudocodes for the median and mean.
Small-Group Instruction During Exploration, small-group instruction is done, about 10 minutes at a time, with predetermined groups to converse and guide the students in creating their code. This is a great time to talk about conditional statements and how these blocks affect a code.
Flexible Groupings Communication and collaboration are assets in tasks like this. By working in groups, students move around and find a place to work with their peers. The teacher circulates among the students and supports them as needed. The teacher questions students and push their thinking as they create to collect data and to determine the mean and the median..

Prior Knowledge and Skills

To be able to carry out this learning situation, the student must:

  • understand what a pseudocode is;
  • know what measures of central tendency are;
  • be able to use block-based programming software.

Learning Goals

At the end of this learning situation, the student will be able to:

  • determine measures of central tendency using block-based programming software;
  • repeatedly use blocks of conditional statements as well as operator blocks;
  • write efficient pseudocodes;
  • recognize the impact of adding or removing certain data on measures of central tendency.

Criteria According to the Achievement Chart

Skills Criteria
Knowledge and Understanding
  • The student understands the category of blocks "my blocks" in order to create personalized blocks* and to use them.
  • The student uses variables in their code.
Thinking
  • The student writes pseudocodes accurately to collect data, determine the mean, and find the median of the collected data.
  • The student accurately corrects syntax and logic errors in their codes (debugging).
  • The student explains the impact of adding or removing data on the mean and the median.
Communication
  • The student coherently explains the effect of certain blocks, such as operator blocks and control blocks.
  • The student clearly explains the code of their peers.
Application
  • The student creates an effective code to collect the shoe sizes of the students in the class.
  • The student consistently adds blocks of conditional statements into their codes.
Screen shot codes of block “my blocks”. Different adding entries: with text Boolean, and sticker.

* Custom Blocks:  This screenshot shows the menu for creating a new block in the Scratch coding software. 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-based coding software might have an interface that differs from this one.

Materials

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: approximately15 minutes

Assessment can be carried out through…An image of a three-dimensional triangle titled: “conversations“, “observations“ and “productions“.

Ask the students to observe, as a class, the picture below while trying to imagine the mathematical problem that could be associated with it.

Image of a cartoon student thinking of a sequence of 16 different pairs of shoes.

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).

Image of a cartoon student thinking of numbers one to 10. Mean, equals, sum of data, divided by number of data.Number One, 2, 4, 6, 11, 16, and 20.

Example questions:

  • Why do you think some numbers are in bold?
  • What math could be 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…An image of a three-dimensional triangle titled: “conversations“, “observations“ and “productions“.

Getting Ready for Coding 

Explain to the students that data concerning the shoe sizes of the students in the class are to be collected. Using this data, students will create codes to help find the mean and median of shoe sizes in block-based programming software.

For Thought 

  • What data are we looking for?
    We are looking for the shoe sizes of the students in the class.
  • How can 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.
  • Would it be possible to create a code for data collection? What will the code need to do?
    The code should ask for a person's shoe size, add that shoe size to a list, then ask someone else until all the data is 
    collected (a pseudocode could help with this step).
  • Is it easier to code for mean, median or mode?
    Some students might 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 the Review.
  • 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 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 has to sort the data in ascending order, then compare the values to determine which one is found most often in the list.

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 block-based programming software, for this pseudocode?
    Invite students to create the code for the situation that the pseudocode represents. Codes may vary. There are several ways to represent this pseudocode using block-based coding.

Sample code:

Blocks of code:Events block stating ‘’when green flag is clicked’’.Variable block stating, “set “n”” b” one to zero”.Variable block stating, “set 2 “n” ” b” zero”.Variable block stating, “set sum to zero”.Sensing block stating, “ask what your first number is, question mark, and wait.”Variable block stating, “set my variable to motion block stating, “answer’’.”Sensing block stating, “ask what your second number is, question mark, and wait.”Variable block stating, to “n”” b” 2 motion block stating, “answer.”Variable blocks stating, “set sum to operators block 1 “n”” b” plus, “n”, ”b”, “2 “

Note: In this part of the learning situation, the students make the blocks their own by means of which the questions are asked and the value of the variables is modified. If the students have already used the coding software in question, it would be possible to go directly to the next part of the activity, which is the data collection. This activity can also be used as a diagnostic assessment to determine if students have what 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, have students create their code to collect data related to students' shoe sizes, then compile it into a list.

Sample code:

Blocks of code:Events block stating ‘’when green flag is clicked’’. Control block stating, “repeat until operator block “answer no”. Inside 5 nested blocks.A sensing block stating, “ask what is the students shoe size and wait.”Variables block stating, “set shoe size to motion block stating, “answer”.”List block stating, “add, variable block stating, “shoe size” to show size list”.”Variables block stating, “change sum by shoe size.”A sensing block stating, “ask do you have another data value to add, question mark, open parenthesis, answer yes or no, closed parenthesis. And wait. “

Note: Several block-based coding software make block customization possible. 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:

Blocks of code:My blocks stating, “define data entry.”Control block stating, “repeat until operators block “answer, equal, no”.”Inside 5 nested blocks. Sensing block stating, “ask what is the student’s shoe size and wait.”Variables block stating, “set shoe size to motions block stating, “answer”.”List blocks stating, “add variable block stating, “shoe size” to shoe size list”.”Variables block stating, “change sum by shoe size. “A sensing block stating, “Do you have another data value to add, question mark. Open parenthesis, answer yes and no, closed parenthesis, and wait.

Once this block is created, the main code would look like this:

Blocks of codeEvents block stating, “when green flag is clicked.”Lists block stating, “delete all of shoe size lift”. My blocks stating, “data entry.”

Coding to Analyze Data 

Ask students what the computer has to do to find the average shoe size from the data collected. If necessary, the starting image with the mean formula could be redisplayed in order to activate the students' prior knowledge. The mean formula can also be transformed into pseudocode. Invite them to write 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

*shoe size data list

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:

Blocks of codeEvent block stating, “when this sprit clicked.”Variables set stating, “set list number to one.”Variables block stating, “set sum to zero.”Control block stating, “repeat” list block stating, “length of shoe size list.”Inside 2 nested blocks.Variables block stating, “change sum by” list block “item of list number of shoe size list.”Variable block stating, “change list number by one.”Looks block stating, “say join the average shoe size is sum divide length of shoe size list.”

Ask students the following questions:

  • What happens if I add shoe sizes to my list?
  • Will the mean be the same? Why?
  • Could this code be made even more effective?

Note: 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:

Blocks of codeEvents block stating, “when green flag is clicked.”Inside 5 nested blocks. Sensing block stating, “ask what is the students show size and wait.”Variable block stating, “set shoe size to’’ sensing block “answer”.List block stating, ‘’add’’ variable block stating, shoe size list.”Variable block stating, “change sum by shoe size.Caption: This code block allows the shoe size to be added to a running sum during each iteration of the loop.A sensing block stating, “ask do you have another data value to add, question mark. Open parenthesis, answer yes or no, closed parenthesis, and wait’’.

Invite students to create a pseudocode and code to find the median shoe size of the students in the class.

Possible questions:

  • What are the steps to follow 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.)

Pseudocode example::

Variables:   * central value 1

* central value 2

* shoe size data list

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, point out to students that calculating the median takes the same form as calculating the mean. Essentially, the mean of the two central values is found.

Here is a sample code to place the data list in ascending order. Again, the code has been turned into a custom block. This step is helpful, but not necessary.

Blocks of codes:My block stating, “define sort the list ascending.”Control block stating, “repeat” variable block “stating, length of shoe size list.”Inside 2 nested blocks.Control block stating, “repeat” variable block stating, “length of show size list minus One.”Inside 2 nested blocks.Control block stating, “if item list number of shoe size list less then item list number minus one of shoe size list then.”inside 2 nested blocks.List block stating, “insert item list name of shoe size list at list number minus one of shoe size list.”List block stating, “delete list number plus one of show size list.”Variables block stating, “change list number by one.”Variables block stating, list “set list number to 2.”

Short explanation of the logic of the code:

This code works by comparing a value in the list with the neighbouring value. If the value is smaller, the positions of the list elements 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 value.

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 software.

Sample code to find the median:

Blocks of codeControl block stating, “if length of shoe size list mod 2 equals zero then.”Caption: This modules operation block, open parenthesis, mod, closed parenthesis, returns the remainder of a division. An even number divided by 2 will return a value of zero, open parenthesis, ex 6 mod 2, equals, zero, closed parenthesis.”Inside 2 nested blocks. Variables block stating, “set central value to length of show size list divided by 2. Variables block stating, “set median to item central value of shoe size list, plus, item central value of shoe list divided 2.”Control block stating, “else”.Variables block stating, “set median to item length of shoe size list plus 1 divided 2 of shoe size list.”

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?

Blocks of codeControl block stating, “shoe size”.Caption: “a variable is needed to hold the student’s shoe size that will change each time the question is asked.Lists block stating, “shoe size list.”Captions: A list is needed that will compile and contain all the shoe size data obtained.Control block stating, “number of shoe size elements.” Caption: “we need to know the amount of elements, open parenthesis, data points, closed parenthesis, that are present in the, quotation, shoe size list, quotation.
The student forgets to reset the variables to zero.

What happens when your variables are not reset at the beginning of the code?

What is the effect on data entry in the list?

Blocks of codeEvents block stating, “when green flag is clicked.”Variable block stating, “delete all of shoe size list.”Caption: “This code block is the equivalent to a, quotation, set to zero, quotation, statement except it is for lists, exclamation mark.

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.

Blocks of code Events block stating, “start on when green flag is clicked.”Variable block stating, “shoe size”.Caption: “A list is needed that will compile and contain all of the shoes size data obtained.Control block stating, “number of shoes size elements.’’Caption: “we need to know the number of the elements, open parenthesis, data points, closed parenthesis, in the list in order to define the number of iterations for the loop. This question is asked to the students. “Control block stating, “shoe size.”Caption: “A variable is needed to hold the students shoe size that will change each time the question is asked.”Control block stating, “list of numbers.”Caption: Another name of this variable could be, quotation, rank, quotation. It represents the position of the list element being looked at.Control block stating, “sum”. Caption: “This variable keeps track of the sum of the values during data collection.”Control block stating, “central values.”Caption: “This variable is necessary in order to identify the median of the list. It is defined as the quotation, list number, quotation, or the, quotation, rank, quotation, of the middle element of this list after it has been sorted ascending numerically.”
The student fails to create new blocks (custom blocks).

Which block category can help you create new blocks?
What colour is it?

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).

Blocks of codeMy list stating, “defines data entry.”Variable block stating, “set number of shoe size elements to 0.”Caption: This block sets the number of shoes size elements to 0, thus removing any values that were present. This is called initializing a variable.Sensing block stating, “how many shoe size do you wish to enter and wait. Variables block stating, “set of number of shoe size elements to’’ motions block stating, “answer”.”Control block stating, “repeat” variable block stating, “number of the shoe size elements’’. Inside 3 nested blocks.Sensing block stating, ”ask what is the student’s shoe size and wait.”Variable block stating, “ask shoe size to’’ motions block stating, ”answer”.”List block stating, “add’’ variable block stating, “shoe size to shoe size list.”
Blocks of codeMy list stating, ”define sort the list ascending”. Control block stating, ”repeat’’ List block stating, ”length of shoe size list.”Inside 2 nested blocks.Control block stating, “repeat length of show size list minus 1.”Inside 2 nested blocks. Control block stating, ”if item list number of shoe size list less than item list number minus 1 of shoe size list then”.Inside 2 nested blocks.List block stating, “inset item list number of shoe size list at list number minus one of shoe size list. List block stating, “delete list number plus one of shoe size list. “Control block stating, “change list number by one.”Control block stating, “set list number to 2.”
The student fails to create a 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 fails to create a code to order the data 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 fails to create a code to find 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?

Block of code:Operators block and variable block stating, “length of shoe size list, mod 2”.”Caption: The module operation block returns the remainder of the Euclidean division. Used in this fashion, coma, when a 2 is used with the module operation, coma, the code is looking for a remainder of 0.Control block stating, “if length of shoe size list, mod 2 2 equals, zero, then. Caption: Used in conjunction with a condition block, the code seeks to determine whether the length of, quotation, shoe size list, is even, open parenthesis equals 0, closed parenthesis or odd, open parenthesis, not equal to zero, closed parenthesis.

Review

Duration: approximately 15 minutes

Assessment can be carried out through…An image of a three-dimensional triangle titled: “conversations“, “observations“ and “productions“.

Have students walk around the classroom and look at other students' pseudocodes and codes.

  • What do you notice?
  • Are your peers' pseudocodes the same as yours?
  • Are your peers' codes the same as yours?
  • What would you change in your codes? What suggestions would you give to your peers?
  • What are the lessons learned today?

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 creating code related to measures of central tendency in block-based coding software, 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).

Consolidation of Learning

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:

  • Create a 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.
  • Create 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 create 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 create 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 coding software 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 software.
  • Provide a cheat sheet on the function of some more complex blocks, such as operators and conditions.