Programming with Python
Kühne Logistics University Hamburg - Fall 2026
The first 40 minutes are the checkpoint. It starts now, before the investor sits down.
When you’re done: menu → Download → Download Python code → upload the .py to the “Checkpoint 3” assignment on Moodle. No retakes: one sitting.
The green ✅ live checks are provisional. The final grading runs on our side. And take a breath: everything in it was rehearsed in the labs.
Pens down. The checkpoint is behind you. Now the reason today matters.
An hour ago the investor walked into the shop unannounced. It’s due-diligence week: before she signs anything, she wants to see how this place actually runs. Kevin offered her a coffee and a spreadsheet he “mostly trusts.”
She didn’t drink the coffee. She walked to the whiteboard, uncapped a marker, and wrote one question:
“Why is everything built from scratch?”
For five sessions you built everything by hand, on purpose. From today, that changes.
Full details on the AI Tools page.
You spent five sessions learning to think without a co-pilot. Now you get one — and you’ll be the pilot.
The investor’s question has an answer: you shouldn’t build it from scratch. Most of what you need is already written.
import a module, then reach for the tools inside it with a dot: math.ceil(...)Kevin has been hand-rolling arithmetic for months. The standard library did most of it before he was born.
import math: stop rounding by hand130 pastries need to ship. They go in crates of 48. How many crates? You need to round up: a half-full crate still ships as a whole one.
3
130 / 48 is 2.7…; math.ceil bumps it to 3. No fiddling with “if there’s a remainder, add one.” The tool already knows.
from statistics import ...Sometimes you only want a couple of tools, not the whole box. Import them by name and use them directly, no statistics. prefix:
3.9
4.5
One furious review (a 1.0) drags the mean down to 3.9. The investor asked for the typical rating: median sorts the values and hands back the middle one (4.5), unmoved by one angry customer.
Some module names are long, or you’ll type them fifty times. import ... as gives a module a nickname for the rest of the file:
4.5
stats.median is the same tool as statistics.median, just less to type. You’ll meet fixed conventions soon (import pandas as pd); using the community’s nickname makes your code instantly readable to everyone else.
You don’t have to memorize a module. Python will tell you what’s in it and what each tool does:
dir() is the drawer of tools; help() is the little instruction card taped to each one. Between them you can explore any module without leaving your editor.
math.ceil rounds up. Its partner math.floor rounds down, but down from a negative number is the tricky part. What does the last line print?
a) -3 b) -2 c) an error
Predict first. Commit to an answer before the next slide.
a) -3 — floor always heads down the number line, toward more negative. From -2.5, down is -3, not the -2 you’d get by rounding toward zero:
-3
“Down” means smaller, and -3 is smaller than -2. Keep the number line in your head, not the distance to zero.
Open the exercise (scan the QR or type the link):
beyondsimulations.github.io/Introduction-to-Python/notebooks/ex_06_a/
First predict what happens, then run it.
random toolboxThe investor wants to see how the shop copes with a busy day, but the busy day hasn’t happened yet. So we rehearse it with made-up numbers. The random module deals them:
0.9252263675891648
20
latte
[4, 2, 3, 5, 1]
Four tools, four flavors of luck: a raw float, a bounded integer, a pick from a list, and a reshuffle.
The investor leans over and says: “Run it again.” Kevin does, and gets completely different numbers:
[4, 9, 13, 8, 17]
[5, 11, 15, 17, 7]
Two runs, two answers. That’s exactly what random is supposed to do, but it’s useless for due diligence. A projection nobody can reproduce is a projection nobody can trust.
random.seed makes luck repeatablerandom.seed(n) fixes the starting point of the number stream. Same seed → same sequence, every time:
[11, 5, 13, 2, 3]
[11, 5, 13, 2, 3]
Both lines print [11, 5, 13, 2, 3]. The numbers still look random, but now the investor can run it herself and land on the identical result.
Kevin seeds once, then builds two lists the same way, without touching the seed in between. Are first and second equal?
a) different: the second list continues where the first stopped b) equal: the seed is set, so both come out the same c) an error: the stream is empty after three draws
Predict first. Commit to an answer before the next slide.
a) different — a seed doesn’t freeze random, it fixes the whole sequence. The first list eats the first three numbers of the stream; the second list simply continues from number four:
[4, 1, 9]
[8, 8, 5]
To get the same list twice, you re-seed before each run, and that rewinds the stream to the start. One seed, one fixed sequence: that’s the entire job of a seed.
Open the exercise (scan the QR or type the link):
beyondsimulations.github.io/Introduction-to-Python/notebooks/ex_06_b/
First predict what happens, then run it.
import math and statistics for investor-grade counts and averages, then use random (with and without a seed) to rehearse a busy day she can reproduceDownload your .py before you leave. Closing the tab without downloading loses your work, and downloading is exactly how you handed in the checkpoint this morning.
import math, from statistics import median, import ... as for a nickname. dir() and help() show you what’s inside.random deals the luck (random(), randint, choice, shuffle), perfect for rehearsing a day that hasn’t happened yet.random.seed(n) makes luck repeatable. Same seed → same sequence, every run. A projection you can reproduce is a projection an investor can trust.Next episode: one array to rule a thousand orders. The shop’s data has outgrown plain lists, and NumPy turns a thousand numbers into a single, fast object.
New this session: the AI Tools page: how and when to use AI in Part II, and the one-line disclosure habit that goes on every submission from here on.
For more, see the literature list of this course.
Lecture VI - Modules and the Standard Library | Dr. Tobias Vlćek | Home