Monday, August 3, 2015

Variable Ladder of abstraction (Programming classes)

Fifth grade

We started by discussing the homework from last time: drawing a 5 pointed star:
The students had two key questions from this activity:
  1. How do we get the star to close up exactly, making the final stroke end at the starting point? This question we are saving for a later class.
  2. how do we make a regular star (all sides and angles equal)? This served as the focal activity for the rest of the class.
Start with regular polygons
We noticed that a regular pentagram has a pentagon inside. How can we make a regular pentagon? As they wrote programs to meet this challenge, they quickly recognized that they could repeatedly move forward and turn, but the key issue is how much to turn.

I had already prepared this toy to help us investigate that question:

The code is here: Exterior Angles Toy. As desired, they noticed that the exterior angles have to add up to 360 degrees. To get every angle the same, we divide by 5 to get 72 degrees.

As a next step, we had them modify the program to use a for loop.  This opened up an opportunity to explore regular polygons with more (or fewer) sides and, again, the question of what the exterior angles should be.

Variables to the rescue
As we played with examples, we noticed that there are two key part of their code that need to change when they change the number of sides: the number of repeats in the loop and the angle. This leads us to two ideas that we will develop further next week:

  1. use a variable (numberOfSides, or something similar): how, when, why?
  2. get the computer to calculate the correct angle: how, why?

Here are our whiteboard notes from the class:

For reference next time, we will also talk about these ideas based on our flower programs from the prior session (our final session of last term):
  1. Draw a spiral that starts from the inside and grows outward
  2. Draw a spiral that starts outside and shrinks to the center
You can see where we explained the spirals on the whiteboard above.

Grade 6

Parallel to the discussion in Grade 5, we set a sequence of challenges around the use of variables. As it turned out, this was hugely helpful in revealing gaps in the students' understanding.

We started with a simple bullseye program: manual bullseye.

An easy program, now, what if we suddenly decide we want the bullseye to be bigger? The students came up with three solutions:
  1. add a command scale 3, for example, to the beginning of the program. This is a good approach because we then control the size with a single parameter in one location. One problem using this is that we then scale any other movement or drawing in the rest of the program, though that can also be fixed with a "closing" scale command to shrink back to normal size.
  2. manually change all of the parameters for the dots. This actually encompasses many different changes, depending on what relationships you want to preserve between the size of the layers. For the most part, the students chose to preserve the absolute difference in the sizes (e.g., 90-72-54 got changed to 108-90-72). The weakness of this approach shows up right away when the "client" asks to have the size changed again.
  3. add a variable to control the size. 
Again, there were many different ways to incorporate a size variable: linear differences (size - 15), proportional differences (size * 2), or inverse proportionality (300/size). We investigated these different approaches and talked about strengths and differences.

Non-numeric variable
After sorting out some ways to control size, the next "client" demand was to change the color of the black layers to blue and, later, to green. This flagged the fact that we could have a variable that is a number, as with size, or a color, or a string.

Variables allow flexibility
One of the key ideas from using variables is that they give our programs greater flexibility. That's particularly true when we combine with a loop, so, naturally, our last challenge was to try to reproduce the bullseye with a for loop. That was left for homework.

Finish the bullseye version using a for loop, get ready for some unreasonable demands from the teachers to change the number of layers, the sizes, and the colors!

Side note and future reference: 
Other interesting things the students have discovered, but which we didn't have time to discuss:
  • donut loop:
  • nice fish:
  • input/output:
6th Grade Projects
  • Gan chase game
  • Boongie animal sound recognition
  • Titus: space invaders variation
  • Win: car driving game

No comments:

Post a Comment