Wednesday, 9/23
What one row means
Open in a new tab
· press f for fullscreen, o for an overview
The notebook is loading. The first load takes about 25 seconds.
Or run it on your own machine, which is how this course works from the second session on.
- Download
02-lists-and-records.pyinto your project'snotebooks/folder. -
Run
uv run marimo editfrom the project, with no file name. You get a page listing every notebook in it.
uv run 02-lists-and-records.py runs the cells and exits without showing you
anything, which looks like nothing happened. No project yet?
uvx marimo edit opens whichever folder you are in.
·
Jupyter version, which
reads without being run but has no working controls.
TL;DR#
Today put names on what you had already run. A value is not a variable, a variable has a type, and the type decides what an operator does: "10" * 2 repeats the text, 10 * 2 multiplies. Then lists: reading an item by position, taking a slice, running the same lines once per item with for, and keeping only some items with if. Before you write the condition, find out what the rule means. Whether "below 25" includes 25 is a question for whoever set the rule, and < and <= give different answers.
What we covered#
A value on its own does nothing. 16.75 typed into a cell is just a number. cost = 16.75 is a statement: it makes a name and points it at a value. Read the = aloud as "assign 16.75 to cost", which keeps it separate from ==, the one that asks whether two things are equal.
The variables panel shows you what exists. It is the second icon down the left side of a marimo notebook. It lists every name the notebook has defined, with its type and its value, and it updates as you run cells.
Type is something you can read. type(cost) tells you. 16 is an int, 16.75 is a float, "16.75" is a str, and the quotation marks are the whole difference. Python will not add a string to a number; it stops and says so.
Two kinds of division. 1 / 3 always gives a float. 4 // 3 gives 1, the whole-number part. To turn a value into another type on purpose, call the type: int(x), float(x), str(x). That is called a type cast.
Anything that comes from outside your program arrives as text. A form, a CSV file, a database, input(): the value looks like a number and is a string. Convert it before you calculate:
cost = float(input("Enter the cost: "))0.1 + 0.2 is not exactly 0.3, in Python or in any other language, because the computer stores decimals in binary. It rarely matters for analysis. Round when you display a result, and use Python's decimal module when every cent has to be exact. 0.30000000000000004.com explains it language by language.
f-strings put values inside a sentence, and they take formatting instructions:
print(f"The total cost is ${total_cost:.2f}"):.2f is two decimal places. You do not need to memorize that notation. You need to know it exists, so that you can ask your agent for it.
Indexing rules, in one place. Counting starts at zero, so charges[0] is the first item. charges[-1] is the last one. Ask for a position that does not exist and you get an IndexError; ask for position 1.0 and you get a TypeError. charges[1:4] is a slice: it starts at 1 and stops before 4, so you get three items. range(5) stops before 5 for the same reason, which is why it gives 0 to 4.
The loop variable is temporary and you choose its name. In for charge in charges:, charge does not exist before the loop. Python gives it the next item on each pass. A plural name for the list and the singular for each item makes the line read like English. To get each item's position as well, use enumerate:
for position, name in enumerate(names):
print(position, name)elif is one decision; two ifs are two decisions. This is question A in section 3. In a chain of if / elif / else, Python checks from the top and stops at the first true branch, so a 95 prints Pass when the >= 60 test comes first. Split the same code into two separate if statements and a 95 prints both lines. The fix we built in class checks the highest grade first:
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 60:
print("Pass")
else:
print("Fail")Habits worth picking up#
- Keep a playground notebook. Make a second notebook in your
notebooks/folder, call itplayground.py, and use it for trying things out. marimo lets a name be defined in only one cell of a notebook, and today's notebook already definescharges, so experiments with those names belong in the playground. - If
uvor marimo will not start in your repository, delete the.venvfolder inside it and runuv syncin VS Code's Terminal.uv syncrebuilds the environment frompyproject.toml. - Ask your agent to make a loop show its work. "Add print statements so I can see what happens on each pass of this loop" gives you a trace of every variable on every pass. Delete the prints when you understand it.
- When a tutorial says
pip install, ask your agent for theuvversion.uv addrecords the library inpyproject.toml, which is what makes your project run on another machine. - Starting a project of your own: create the repository in GitHub Desktop, open it in VS Code, and use the Copilot chat with your Babson key. The second half of the Babson AI Key guide sets that up.
Data Centers#
The talk proposed heating community swimming pools with a data center's waste heat. The discussion after it covered why towns push back on new data centers: the water they draw for cooling, higher electricity prices in the surrounding area, and noise. Data-center demand is also one reason memory and storage have become more expensive for everyone else. The case for building them is that companies expect demand for AI to grow well beyond today's, as more devices run models. We will come back to this when the course reaches AI agents.
Public links#
- Babson AI Key, including the VS Code setup
- Python Projects,
uv init,uv add, and where each kind of file goes - What to Commit, and what should never reach github.com
- PEP 8 naming conventions, where
snake_casefor names comes from - The Zen of Python, which you can also read by running
import this - Faker, the library that makes fake names, addresses and phone numbers
- xkcd 353, the comic behind
import antigravity, and xkcd 1987, on Python environments
Before next session#
- Finish section 3 of the notebook,
3. ✏️ Your Turn. A to E are the required ones, and we worked through A together. The ones under If You Finish are there for anyone who wants more. Each question has its code in a cell already, and a check value to test your answer against. - Commit and push. The commit you make at the end of class is part of your participation, and so is the work you push afterwards. Saving is not pushing.
- Sections 4 to 6, on records and tables, will open next session. They are not this week's work.
Checkpoint 2 covers this session and the next one. The checklist is on Canvas, and it grows as each session it covers is taught.
In the handbook
Reference for this session. None of it is assigned.