C3.2 Read and modify given codes, including codes with conditional statements and other control structures, and describe the impact of these changes on the results.

Activity 1: Counting in one-fifth increments and conditional statements/control structures


Ask students to read the code below that counts in one-fifth increments.

Blocks of code:Events block station “start on when green flag is clicked”.Variable block stating “stating fifths to ‘0’.”Variable block stating “stating all to ‘0’.”Control block stating “repeat ‘10’.”Inside 4 nested block.Variable block stating “change fifths by ‘1’.”Variable blocks stating “if fifths, equals, ‘1’, then”.Looks block stating “say join fifths fifth for ‘2’ seconds.”Looks block stating “say join fifths fifth for ‘2’ seconds.”

Then ask them to modify the code to obtain the following conditions:

  • If the count reaches a whole, a sound is heard or a movement is seen.

Example

Blocks of code:Events block station “start on when green flag is clicked”.Variable block stating “stating fifths to ‘0’.”Variable block stating “stating all to ‘0’.”Control block stating “repeat ‘10’.”Inside 4 nested block.Variable block stating “change fifths by ‘1’.”Variable blocks stating “if fifths mod ‘5’ equals ‘0’.”Looks block stating “next costume” Variable block stating “change fifths by ‘1’.”Looks block stating “say join fifths fifth for ‘2’ seconds.”Looks block stating “say join fifths fifth for ‘2’ seconds.”Looks block stating “say all join and join fifths fifths.”
  • Whenever a set is complete, the number of sets is displayed.

Example

Blocks of code:Events block station “start on when green flag is clicked”.Variable block stating “stating fifths to ‘0’.”Variable block stating “stating all to ‘0’.”Control block stating “repeat ‘10’.”Inside 7 nested block.Variable block stating “change fifths by ‘1’.”Variable blocks stating “if fifths, equals, ‘1’, then”.Looks block stating “say join fifths fifth for ‘2’ seconds.”Looks block stating “say join fifths fifth for ‘2’ seconds.”Variable block stating “if fifths, equals, ‘5’ then.”Lists block stating “change all by ‘1’.”List block stating “set fifths to ‘0’.”Looks block stating “say join all join and join fifths fifths.
  • The code counts up to 10.

Example

Blocks of code:Events block station “start on when green flag is clicked”.Variable block stating “stating fifths to ‘0’.”Variable block stating “stating all to ‘0’.”Control block stating “repeat ‘10’.”Inside 7 nested block.Variable block stating “change fifths by ‘1’.”Variable blocks stating “if fifths, equals, ‘1’, then”.Looks block stating “say join fifths fifth for ‘2’ seconds.”Looks block stating “say join fifths fifth for ‘2’ seconds.”Variable block stating “if fifths, equals, ‘5’ then.”Lists block stating “change all by ‘1’.”List block stating “set fifths to ‘0’.”Looks block stating “say join all join and join fifths fifths.

Activity 2: Financial literacy, conditional instructions and other control structures


Ask students to read the following code:

Events block stating ”start on when green flag clicked.”Variable block stating ”set taxe rate to ’0, decimal, 13.”Variable block stating ”subtotal to ’0’.”Sensing block stating “ask what is the cost of the item and wait”.Variable block stating “set subtotal to answer”.Sensing block stating “ask would you like to calculate the total of the items with tax. Parenthesis, yes or no, parenthesis, and wait.”Control block stating “if answer, equals yes, then.”Inside 3 nested blocks.Looks block stating “say join the total amount of tax join round subtotal, multiplication, tax rate, multiplication, 100, division, 100, dollars for 2 seconds.”Looks block stating “say join the total purchase amount is join round subtotal, multiplication, one, plus, tax rate, multiplication, 100, division, 100, dollars for 2 seconds.Looks block stating “stay join the total purchase amount without tax will be join subtotal dollars.

Questions to ask students Changes to be made
If we move the boxed part inside the condition block, will the code result be different? Explain your reasoning.

Blocks of code:Events block stating “start on when green flag is clicked”.Sensing block stating “ask what is the cost of the item, question mark, and wait”.Variable block stating “set subtotal to answer”Sensing block “ask would you like to calculate the total of the items with tax, quesiton mark, yes or no, and wait”.Control block stating “if answer, equals, yes then”.Inside 5 nested blocks. Variable block stating “set tax rate to, 0 decimal 13”.Variable block stating “subtotal to 0”.Looks block stating “say join the total amount of tax join round subtotal, multiplication, tax rate, multiplication, 100, division, 100, dollars for 2 seconds.”Looks block stating “say join the total purchase amount is join round subtotal, multiplication, one, plus, tax rate, multiplication, 100, division, 100, dollars for 2 seconds.Looks block stating “stay join the total purchase amount without tax will be join subtotal dollars.

Is it possible to modify the code to calculate the cost of several items?

Example of the code

Events block stating “start on when green flag clicked”. Variable block stating “set tax rate to 0, decimal, 13.”Variable block stating “subtotal to 0.”Lists block stating “delet all items.”Control blocks stating “repeat until answer, equals, no.”Inside 3 nested blocks.Sensing block stating “ask what is the cost of the item, quesiton mark, and wait.”Variable block stating “add answer to items.”Sensing block stating “would you like to add another article and wait”.Control blocks stating “repeat length of items”.Inside 2 nested blocks.Variable block stating “change subtotal by item item number of items”.Variable block stating “change item number by 1.”Sensing block stating “ask would you like to calculate the total of the items with tax, question mark. Parenthesis, yes or no, parenthesis, and wait.”Control block stating “if answer equals yes then”.Inside 3 nested blocks.Looks block stating “say join the total amount of tax join round subtotal, multiplication, tax rate, multiplication, 100, division, 100, dollars for 2 seconds.”Looks block stating “say join the total purchase amount is join round subtotal, multiplication, one, plus, tax rate, multiplication, 100, division, 100, dollars for 2 seconds. Looks block stating “say join the total purchase amount without tax will be join subtotal dollars.

Is it possible to change the tax rate based on the Canadian province or territory?

  • Create variables for each province and territory to provide choice.
  • Request the tax rate with a "request" block.