Lab 1: Games

Developers, see Unit 2 Lab 1 Pages 1-2 tips and videos on Piazza.

Lab pages have been renumbered (pg 1 split into two and page 4 dropped). Need to adjust TG. --MF, 3/21/19

Students build a number-guessing game in which the player tries to guess the computer's secret number, and the computer responds with as human-like dialog as the programmer can build. Students gain more experience with conditionals and predicates, preparing them to refine and deepen their understanding in lab 3.

This game comes back more than once in later units, because it's the canonical example of a binary search strategy. If you notice that some students always guess 5 first, while other kids start with 1 or 10, and if there's time at the end of the week, consider a class discussion of strategies.

This lab also expands students' understanding of variables. Students have encountered variables in two contexts: they have created blocks that have input variables, usable only inside the block for which they were created; and they have used the for block, which provides an index variable (i.e., a counter), usable only in the script that contains the for block. This lab introduces script variables (a kind of local variable), created by the script variables (a) block, which lets programmers create their own temporary variables in which to store information that a script needs while it is running. A script variable is called "local" because it exists only while that script is active and is accessible only by blocks inside that script. Blocks inside that script can set, use, or change the value of that script's variables; blocks outside that script cannot. Index and input variables are also local. By contrast, a global variable is accessible by any block in any script belonging to any sprite: it is global in scope.

It's traditional in teaching programming to start with global variables, on the theory that they're easier to understand. We take pains to teach global variables last, so that students get practice dealing with limited-scope variables early. This lets us teach good programming style without hectoring students about it.

Students take time to debug each portion of their project. They get suggestions for features to add but are on their own to think about how to structure these extensions and modifications so that the code works and remains clear.

Pacing

The 5 lab pages could be split across 2–4 days (75–150 minutes). Expected times to complete follow:

Lab Pages

Solutions

Correlation with 2020 AP CS Principles Framework 

Computational Thinking Practices: Skills

Learning Objectives:

Essential Knowledge: