Class 1 - Numbers
Date: September 9, 2026
Skills: None
Notes (review after class)
Read this after today's class.
Motivating Example: Flags
Our first goal: a program that makes images of flags, in different sizes.
- Try: write down what you notice about these flags, and what you wonder about them. Noticing features of data is an essential skill in computing.
- Some share a structure with different colors; some come in several sizes. So we need numbers (to compute stripe heights from the flag's size), strings (to name colors), and expressions (to make and combine images of shapes).
Arithmetic
Our programming environment, PLL (in vscode.dev), evaluates, or runs,
what we write: type 3 + 5 at the interactions prompt and press Enter, and the
result, 8, appears below it. (Press Up to get back what you typed, and edit it.)
- Python follows math's order of operations:
3 + 4 * 5is23, and(3+4) * 5is35. - Spaces and parentheses are optional, but help readability. Our
Style Guide puts spaces around operators (
3 + 4), but where priorities are mixed, only around the lowest-priority ones, so the spacing shows the order:3 + 4*5. Add parentheses whenever the order isn't obvious. min(2, 8)is the smaller number,2;maxgives the larger.
Expressions
min gives back a number, just like +, so its result can go anywhere a number
can:
5 * min(2, 8)
(1+5) * min(2, 8)
- These produce
10and12: bigger computations are built from smaller ones. - Try: "subtract 3 from 7, then multiply by 4"; "2 divided by the sum of 3 and 5".
Two Kinds of Numbers
- Integers (
int), like8, are always exact. - Floating point numbers (
float), like4.0or0.25, have a decimal point, and can only represent most numbers approximately (try0.1 + 0.2). /always produces afloat, even when the answer is whole:8 / 2is4.0.
Terminology
- Expression: a computation in the formal notation of a programming
language, like
4,5 + 1, or(3+4) * (5+1). - Value: an expression that can't be computed further, like
42or4.0. - Program: a sequence of expressions that you want to run.
Recap (25 mins)
Goal Describe what course is about, set up the Python environment.
This course is called "Introduction to Program Design and Implementation".
- Re-iterate -- for people who do not know how to program. Describe 2100.
- Can anyone tell me what they think a program is?
- written constructs, that have precise meaning -- instructions of how to do something, carry out operations, etc.
- What does the word Implementation here mean?
- once you know what a program should do, how it should be organized, actually writing it down requires understanding precise rules. And often, the first time you write it down, it isn't right -- implementation also covers the idea of validating it, making sure it actually behaves as you expect.
- What does the word Design here mean?
- the languages we used to write programs allow us to very quickly make programs that are hard to understand, possibly even by the person that wrote them. We use Design here to stand for skills to organize our programs so that they are easy to write, easy to understand, and easy to modify -- and this ends up being much more important (and thus, occurs first) than whether they "work" (the Implementation part), given "working" is usually only a temporary state, until requirements for the program change.
What is Python?
Python is a programming language that is now the most widely used language in the world, in industry, science, and education. Since Python was designed for professional programmers, we use it through a tool designed explicitly for computer science education, and just like designing our programs results in better programs, designing our tools can help get better results. That tool is an extension to the VSCode editor called Python Language Levels (PLL): it runs Python for you, shows you results (including images and tables!), and depending on the level that you choose, checks your programs for common mistakes, and explains errors in ways that are easier to understand. This allows us to teach you more than we would be able to otherwise.
How do we use Python?
All editing, throughout the semester, will happen in the browser, using an editor called vscode.dev.
-
Go to https://vscode.dev.
-
Click the Extensions icon in the left sidebar (the four squares).
-
Search for Python Language Levels.
-
Click Install. If it asks you to trust the publisher, do that.
-
If vscode.dev offers to install Microsoft's Python extension, don't. We are using Python Language Levels, not that one.
-
Open the Command Palette (
Ctrl+Shift+Pon Windows,Cmd+Shift+Pon a Mac) and run PLL: Show Interactions. A PLL panel will open at the bottom of the window: this is the interactions panel, and it has a prompt at the bottom where you can type Python and press Enter to run it.The first time you run something, it can take a little while: PLL is loading Python in the browser. Later runs are faster.
First Expressions
Show the editor vs the interactions panel. Most of the time, we'll write our programs in files in the editor, and use the interactions panel to see the results, and to try things out. Today, we only use the interactions panel. Type these at the prompt, one at a time; each comment shows the value that appears:
2 + 3 # 5
5 * 4 # 20
18 / 3 # 6.0
2 + 3*4 # 14
(2+3) * 4 # 20
2 + (3*4) # 14
- Each line is an expression, and each comment is its value. Why is the value of
18 / 3written6.0, when the value of5 * 4is written20? - The last three lines use the same numbers and operators. Why do two of them
give
14and one20? How does the spacing of2 + 3*4hint at its value? - Predict, then try:
2 * 3+4(spaced the "wrong" way),10 / 4, and10 - min(2, 8).
Course Website
Show course website -- including notes & exercises for today. Today's Notes section is to be reviewed after class, but for all other classes, the Notes section at the top of the page is to be reviewed before class.
Class Exercise (15 mins)
- Calculate the area of a rectangle with length 10 and width 3.
- Calculate its perimeter.
- Note that many different expressions can produce the same value. Come up with
three different expressions that all evaluate to the value 10. Do all of
them produce the same value? (Is
10.0the same as10?) - Evaluate
0.1 + 0.2. What do you notice?floats can only represent most numbers approximately, so calculations with them can produce results that are very slightly off.ints, on the other hand, are always exact.
Wrap-up (20 mins)
- Share any errors you encountered.
- Go over Skills how this impacts grades on syllabus, how every element of course website ties back to skills. Talk about Assignment Chats, Pair Programming. Talk about AI policy, collaboration policy (the rest they can probably read).