C3.2 Read and alter existing code, including code that involves sequential, concurrent, and repeating events, and describe how changes to the code affect the outcomes.
Activity 1: Geometric Reasoning
Have students observe and read the following three codes.
image Blocks of code:Events block stating “start on when green flag is clicked”.Motions block stating “go to x: ‘0’ y: ‘0'.Pen extension stating “erase all”Motions blocks stating “point in direction ‘90’.”Pen extension stating “pen down”. Motions block stating “move ‘100’ steps. “Motions blocks stating “ turn left ‘90’ degrees. Motions block stating “move ‘100’ steps. Motions blocks stating “ turn left ‘90’ degrees. Motions block stating “move ‘100’ steps.Motions blocks stating “ turn left ‘90’ degrees. Motions block stating “move ‘100’ steps.Motions blocks stating “ turn left ‘90’ degrees. image Blocks of code:Events block stating “start on when green flag is clicked”.Motions block stating “go to x: ‘0’ y: ‘0'.Pen extension stating “erase all”Motions blocks stating “point in direction ‘90’.”Pen extension stating “pen down”.Controls block stating “repeat 3”.Inside are 3 nested blocks.Motions block stating “move ‘200’ steps”. Motions block stating “turn right ‘120’ degrees”. Control block stating “wait ‘1’ seconds. image Blocks of code:Events block stating “start on when green flag is clicked”.Motions block stating “go to x: ‘0’ y: ‘0'.Pen extension stating “erase all”Motions blocks stating “point in direction ‘90’.”Pen extension stating “pen down”.Controls block stating “repeat 2”.Inside are 6 nested blocks.Motions block stating “move ‘200’ steps”. Motions block stating “turn right ‘90’ degrees”. Control block stating “wait ‘1’ seconds.Motions block stating “move ‘100’ steps”.Motions block stating “turn right ‘90’ degrees”.Control block stating “wait ‘1’ seconds”.
Ask the following question: What are the outcomes?
Ask students to explain their reasoning.
Activity 2: Repeat Addition/Multiplication
Ask students to read the following codes.
image Blocks of code:Events block stating “start on when green flag clicked”. Variable blocks stating “set my variables to ‘0’”. Control blocks stating “wait ‘2’ seconds”. Variable blocks stating “change my variables to ‘200’”. Control blocks stating “wait ‘2’ seconds”.Variable blocks stating “change my variables to ‘200’”.Control blocks stating “wait ‘2’ seconds”.Variable blocks stating “change my variables to ‘200’”.Control blocks stating “wait ‘2’ seconds”.Variable blocks stating “change my variables to ‘200’”.Control blocks stating “wait ‘2’ seconds”.Variable blocks stating “change my variables to ‘200’”. image Blocks of code:Events block stating “start on when green flag is clicked”. Variables block stating “set my variables to ‘0’.”Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’Variables block stating “change my variables to ‘100’
Use the following questions to engage students in mathematical discussions:
- What are the similarities?
- What are the differences?
- Is it possible to alter the code without affecting its outcome?
Variation: A similar code could be used for repeated subtraction/division.
Ask students the following question: In the codes below, does the location of the loop affect the outcome?
image Blocks of code:Events block stating “start on when green flag is clicked. Variables block stating “set my variables to ‘0’.”Control block stating “wait ‘1’ seconds”.Control blocks stating “repeat 10”.Inside are 2 nested blocks.Controls block stating “wait ‘1’ seconds.”Variables block stating “change my variables by ‘100’.” image Blocks of code:Events code stating “start on when green flag is clicked”.Controls block stating “wait ‘1’ seconds”. Controls block stating “repeat 5”. Inside are 3 nested blocks.Variable blocks stating “set my variable to ‘0’.”Controls block stating “wait ‘1’ seconds”. Controls block stating “change my variable by ‘200’.
Ask students to explain their reasoning.