$ cat checkpoint-1.md

Concept Checkpoint 1

Wednesday, September 23, in class, on paper. Fifteen multiple-choice questions, closed notes, no devices. It covers Weeks 2 through 4, and it is worth 3 points under Concept Checkpoints on the syllabus.

Concepts to review

Each group links to the slides it comes from. The Try It boxes on those slides are the best practice: predict what each one prints, then run it.

The terminal and Git slides

working directory
The folder you are working inside right now. pwd prints its path, ls lists what is in it, cd NAME moves into a folder, cd .. moves up one level, mkdir NAME creates a folder.
repository
A folder that Git is recording. Every activity and lab is one. git clone URL downloads a copy of it onto your computer.
git add, commit, push
git add marks a file for the next save, git commit -m "message" saves a snapshot on your laptop, git push uploads your snapshots to GitHub. A commit on its own stays on your laptop.

Variables and types slides

variable
A name that stores a value: trip_miles = 450. The single = means store this, not equals.
the four types
int (26), float (3.79), str ("Wednesday"), bool (True or False).
input()
Pauses the program, waits for a line, and hands back what was typed as a string. Always a string, even when the user typed a number.
int(), str(), float()
Convert between types: int("26") is 26, str(26) is "26". int("3.5") is an error; go through float() first.
f-string
print(f"Trip: {trip_miles} miles") drops the value into the text and converts it for you.

Arithmetic slides

/
Division. It always gives a float: 10 / 5 is 2.0.
//
Integer division. It throws the remainder away: 2026 // 100 is 20.
%
Modulo. It keeps only the remainder: 11 % 7 is 4. Anything that wraps around, like clocks and weekdays, is modulo.
.split()
"11-25-2026".split("-") gives ["11", "25", "2026"]. Every piece is still a string. Convert before you calculate.

Strings slides

joining with +
"Good" + "bye" is "Goodbye". No space appears unless you put one there. "Room " + 101 is an error; "Room " + str(101) works.
repeating with *
"ha" * 3 is "hahaha", and "=" * 50 is a banner line. The count has to be an int.
three ways to print
print("Total:", total) puts a space between the pieces for you. print("Total: " + str(total)) joins, so every character is yours. print(f"Total: {total}") converts for you.
len()
len("Lovelace") is 8, the number of characters, as an int.

Comments and markdown slides

comment
Everything after # on a line is skipped when the program runs. Comment the why, not the what: a comment that restates the line says nothing.
docstring
The triple-quoted block at the top of main.py. Its Author: line is yours to fill in.
markdown
Plain text plus a few marks: # for a heading, **bold**, *italic*, > for a quote. A blank line separates paragraphs.

Conditionals slides

comparison
A question Python answers with True or False: 5 > 3, score == 100, name != "". <= and >= allow the equal case; < and > do not.
= versus ==
= stores a value. == asks whether two values are equal. An if needs the question.
block
The indented lines under a line that ends in a colon. Indentation is the only thing that marks where a block starts and ends.
if, else, elif
The if block runs when its condition is True. else runs when it was False. elif adds another condition, checked only if every one above it was False.
order matters
Python checks a chain top to bottom, runs the first branch that is True, and skips the rest. A wide condition placed first catches cases meant for a narrower one below it.
nesting
An if inside another if block is only reached when the outer one was True.

The Pico 2 W slides

microcontroller
The Pico runs one program at a time, straight against the hardware. Its GPIO pins send or read a 3.3 volt signal.
Pin("LED", Pin.OUT)
from machine import Pin gives you control of a pin. "LED" names the built-in LED, and Pin.OUT means your code controls it.
led.on(), led.off()
led.on() sends 3.3V through the pin and the LED lights. led.off() drops it to 0V.
time.sleep()
import time, then time.sleep(0.5) pauses the program for half a second. Without a pause, on and off happen faster than your eye can see.

The question formats

One example of each question format, with its answer under the fold. None of these exact questions is on the quiz.

1 What does this program print?

Trace the program by hand, one line at a time, and pick the exact output. Spaces and quotation marks count.

minutes = 145
print(minutes // 60, minutes % 60)
  1. A. 2 25
  2. B. 2.4 25
  3. C. 2 5
  4. D. 145 60
Show the answer

A. 145 // 60 is 2 (the remainder is thrown away), 145 % 60 is 25 (only the remainder is kept), and the comma prints a space between them.

2 Which line produces this output?

You are given the output and pick the line of code that prints it. Watch where the spaces land.

name = "Ada"
# which line prints exactly:  Hello, Ada!
  1. A. print("Hello, " + name + "!")
  2. B. print("Hello,", name, "!")
  3. C. print("Hello, name!")
  4. D. print("Hello, " + "name" + "!")
Show the answer

A. Joining puts exactly the characters you wrote. B prints a space before the exclamation mark, and C and D print the word name instead of the value.

3 A term and its definition

A word from the course, and you finish its definition.

A comment is …

  1. A. a line Python skips when the program runs, written for the people reading the code
  2. B. a line that prints a message to the user
  3. C. an instruction Python runs before anything else
  4. D. a note that GitHub adds to your file when you push
Show the answer

A. Everything after # on a line is ignored by Python. Comments exist for humans, which is why they should explain the why and not restate the line.

4 Which statement is true?

A definition or a fact about how Python behaves, with no code to trace.

  1. A. input() returns an int when the user types digits
  2. B. input() always returns a string, whatever the user types
  3. C. input() returns a float
  4. D. input() returns True or False
Show the answer

B. input() hands back the line as typed, as a string. Converting it is your job, with int() or float().

5 What does this expression evaluate to?

A comparison on its own. The answer is True or False, and print can show it.

temperature = 72
print(temperature >= 70)
  1. A. True
  2. B. False
  3. C. 72
  4. D. An error
Show the answer

A. 72 is greater than or equal to 70, so the comparison is True, and print shows True.

6 Which condition matches the description?

A rule in plain words. Pick the comparison that says the same thing.

# print a freeze warning when the temperature is below 32
  1. A. temperature <= 32
  2. B. temperature < 32
  3. C. temperature > 32
  4. D. temperature = 32
Show the answer

B. "Below 32" does not include 32, so it is <. <= would warn at exactly 32, and = stores a value instead of comparing.