Instructional Material: CoderZ PseudoCode Exercise

Printer-friendly version

This Pseudocode exercise is from the CoderZ Amazon Cyber Robotics Challenge (2020) Teacher's Guide (page 23):

Pseudocode, Compare and Refine: Draw those Shapes (20 - 30 minutes)

Overview:
Students will use pseudocode to write two sets of simple instructions. One to draw a square and the other a rectangle. Students will then look for places where using iteration, repeat loops, could shorten their code and make it more efficient.

Materials:
> Graph paper
> Pen or pencil

Objective:
To reinforce the concept of iteration by having students write out the repeated steps of an algorithm.
Students will review the instructions to carry out a simple activity, then look for places where using iteration could shorten their code and make it more efficient.

Instructions:
Review the properties of a square.
> Four sides of equal length
> Four 90 degree right or left turns (to form a square they must select one or the other and stick with it.

Have the students write the pseudocode, line by line, to draw a square the size of 4 units by 4 units (each unit represents a square on the graph paper). Pretend the pen/pencil is shaped like an arrow and upon the completion of each turn it will be facing forward along the direction just turned. When first placed on the graph paper it will be facing right.

Sample Pseudocode Line by Line:
> Pick up pen/pencil
> Place the writing end of the pen/pencil on the upper-left corner of a square on the paper
• Move 4 units forward
• Change drawing direction by 90 degrees to the left
> Move 4 units forward
> Change drawing direction by 90 degrees to the left
> Move 4 units forward
> Change drawing direction by 90 degrees to the left

> Move 4 units forward
> Lift the pen/pencil from the graph paper
> Lay the pen/pencil down on the table
> Now have the students edit the Pseudocode using a Repeat Loop.

Sample Pseudocode with Repeat Loops:
> Pick up pen/pencil
> Place the writing end of the pen/pencil on the upper-left corner of a square on the paper
> Repeat 4 times
• Move four units forward
• Change drawing direction by 90 degrees to the left
> Lift the pen/pencil from the graph paper
> Lay the pen/pencil down on the table

Reflection:
How does using a repeat loop simplify the coding process?
> Answers may include:
• Less code, less time to enter
• Less code, less opportunity to make mistakes
• Easier to edit

Why would anyone write pseudocode?
> Answers may include:
• Concentrating on the end results instead of the code itself.
• Pseudocode is concise so it is more readable and easier to modify.
• Once the pseudocode is written it is easier to write the actual code using a programming language.

Iterate:
You may repeat this process, only this time have them create a rectangle. (Hint: this will require only a repeat of 2 times instead of 4.)
Feeling adventurous? Try an equilateral triangle or hexagon.
NOTE: Be sure to have students complete the task line by line first and then use the repeat loops.

Material Type: 
Lab Activity
HW Platform: 
SW Platform: 
Interactivity Style: