In class, we worked through this sequence of questions in random groups at the whiteboards.

If you were away

You need no computer for this. Work through the questions below in order, before looking at any answers. Each question builds on the one before it. Surprised by what you discover in a given question? That is where the learning happens.

Once you have an answer, expand the answer box to check your work. If a question didn’t go the way you expected, try to explain why before moving on.

When you reach the end, read the summary of key ideas that we built together in class.

Part 1: which one doesn’t belong?

Copy this grid onto your board.

7"7"
7.5false

Question 1

Each of you picks the one that doesn’t belong, and gives a reason. There is more than one right answer.

Question 2

Find a reason for every corner. Write the reason beside it.

Question 3

7 and "7" look almost the same. Would 7 + 7 and "7" + "7" give the same answer? What do you think a computer does with each?

Question 4

Sort the four values into kinds: a whole number, a number with a decimal point, some text, a yes-or-no answer. Then add one new value of your own to each kind.

Question 5

Where in a game would you use each kind? Give one example for each.

Part 2: an AP exam question

The AP exam writes code in its own way. The arrow ← means work out the value on the right, then store it in the name on the left. DISPLAY shows a value on the screen; in Swift, print does the same job.

Question 6

Read this line aloud, then say in your own words what it does.

a ← 5

Question 7

Now trace these two lines. What does b hold at the end? Is b linked to a from now on, or does b have its own copy?

a ← 5
b ← a

Question 8

Here is the next line. Does it make sense as a math equation? What does the computer do with it?

a ← a + 3

Question 9

Put it all together. What does this code display?

a ← 5
b ← a
a ← a + 3
DISPLAY(b)
DISPLAY(a)

(a) 5 8

(b) 8 8

(c) 5 5

(d) 8 5

Question 10

Someone chose (b). What did they think was happening? Someone else chose (c). What did they think?

Question 11

Write all five lines in Swift. Use let or var, give each name its type, and use print where the AP code says DISPLAY.

Bonus

Predict: what does a computer answer for 7 / 2? Is it 3.5, or something else? Write your prediction down. You test it for real later today.

Summary of key ideas

Here is the summary of the concepts we consolidated together in class, after the whiteboard work:

Data Types, Assignment, and Tracing

NOTE

If the whiteboard conversation didn’t quite click, or you were away, this is the document to read for a concrete summary of the key ideas: the four kinds of value and their Swift names, how to tell them apart by how they are written, what the arrow and = really do, and how to trace a few lines of code with a table.

Curriculum connection

A1.1

use constants and variables, including integers, floating points, strings, and Boolean values, correctly in computer programs;

Link to original

A1.3

use assignment statements correctly with both arithmetic and string expressions in computer programs;

Link to original

AAP-1.A

Represent a value with a variable.

AAP-1.A.1 A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values.

AAP-1.A.2 Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.

AAP-1.A.3 Some programming languages provide types to represent data, which are referenced using variables. These types include numbers, Booleans, lists, and strings.

AAP-1.A.4 Some values are better suited to representation using one type of datum rather than another.

Link to original

AAP-1.B

Determine the value of a variable as a result of an assignment.

AAP-1.B.1 The assignment operator allows a program to change the value represented by a variable.

AAP-1.B.2 The exam reference sheet provides the “←” operator to use for assignment. For example,

Text:

a ← expression

Block:

a ← expression

evaluates expression and then assigns a copy of the result to the variable a.

AAP-1.B.3 The value stored in a variable will be the most recent value assigned. For example:

a ← 1
b ← a
a ← 2
display(b)

still displays 1.

Link to original