Programming with Python
Kühne Logistics University Hamburg - Fall 2026
Overnight the city banned delivery after 22:00. Your app can no longer just say yes to every order. Today the code starts making decisions, repeating work over every order, and tidying up Tobi’s menu.
(Tobi’s fix: “we just deliver yesterday’s orders the next morning.” A lawyer disagreed.)
Three questions from Episode 1. Commit. Hands up before the reveal.
a) 17.8 b) 17.80 c) Error
b): :.2f always prints two decimals. That’s the whole receipt trick.
a) float b) int c) str
c): quotes make it text, no matter how numeric it looks. (Tobi learned this the hard way.)
a) 3.5 1 b) 3 1 c) 3 0.5
b): // floors, % gives the remainder. Together: “how many fit, what’s left.”
A comparison asks a question and answers with a boolean: True or False, the bool type you met last week:
True
False
Six operators, all returning True or False:
< less than · > greater than<= at most · >= at least== equal · != not equal= assigns a value; == compares two values. Mixing them up is the classic first-week bug.
and, or, not glue booleans together:
True
and needs both sides true; or needs at least one; not flips it.
if: do something only whenAn if runs its indented block only when the condition is True:
Open: send the courier.
The indentation (4 spaces) is what marks the block. Python is strict about it.
if / else: two pathselse catches every case the if missed:
Curfew: kitchen closed.
if / elif / else: a ladderMore than two cases? Stack elif branches. Reward loyal customers by tier:
Silver
Tobi rewrote the tier ladder “to keep the common case on top”. A customer with 25 past orders walks in. Which tier do they get?
a) Gold b) Bronze c) Silver
Predict first. Pick a letter, then I reveal the answer.
c) Silver: Python checks branches top to bottom and takes the first True one. 25 >= 5 is already True, so the Gold branch is never even looked at. Order your ladder from strictest to loosest.
Silver
(One misplaced elif and Tobi demotes every VIP.)
The curfew is 22:00. An order comes in at exactly 22:00. What prints?
a) False b) True c) Error
Predict first. Pick a letter, then I reveal the answer.
22 < 22a) False: < is strict. 22 is not less than 22, so at 22:00 sharp the kitchen is already closed. Use <= when the boundary should count.
False
Open the exercise (scan the QR or type the link):
python.tobiasvlcek.com/notebooks/ex_02_a/
First predict what happens, then run it.
Tobi totals the day’s orders by hand, one print per order:
Falafel Wrap
Pad Thai
Miso Ramen
Three lines for three items. A hundred orders? A hundred lines. There is a better way.
for: one step for every itemA for loop runs its block once for each item in a list:
Falafel Wrap
Pad Thai
Miso Ramen
item is the loop variable. It takes each value in turn, and the name is yours to choose.
Start a total at 0, then add each item as the loop visits it:
15.0
After the loop, total holds the sum. This is how you replace Tobi’s hand-counted dashboard.
range(): count without a listrange(n) counts from 0 up to, but not including, n:
0
1
2
Three passes: 0, 1, 2. (It stops before 3, a beginner’s favorite surprise.)
range() with two and three argumentsrange(start, stop): begin at start, stop before stoprange(start, stop, step): jump by step each time[2, 3, 4]
[0, 3, 6, 9]
A string is a sequence too, and a for loop walks it character by character:
P
a
d
A list comprehension is a for loop compressed into one line that builds a list:
[8, 10, 12]
Just a taste. Session IV gives comprehensions their proper treatment. For now: recognize the shape.
print run?The print is not indented. What does this show?
a) 10 b) 10 then 30 c) 30
Predict first. Pick a letter, then I reveal the answer.
printc) 30: print sits outside the loop, so it runs once, after the loop finishes, showing the final total. Indent it and it would print on every pass. Indentation decides what repeats.
30
Open the exercise (scan the QR or type the link):
python.tobiasvlcek.com/notebooks/ex_02_b/
First predict what happens, then run it.
while: repeat as long asA while loop repeats as long as its condition stays True. Suppose MunchCorp undercuts you. Cut your price each round until you drop below their price:
2 6.4
Two rounds and you’re under 7.00. (The lab’s price war against MunchCorp is your boss fight after the break.)
Every pass must nudge the condition closer to False: here the price shrinks, so the loop is guaranteed to end.
If nothing changes, the condition never flips and the loop runs forever:
An endless while will freeze your marimo tab. Always check that something inside the loop changes the condition.
break: an early exitbreak jumps out of a loop immediately, handy with while True:
3
The loop would run forever, but break stops it the moment count hits 3.
Tobi typed the daily special IN ALL CAPS with stray spaces. Strings have methods that return a cleaned-up copy:
miso ramen
Miso Ramen
SPECIAL
moin
Methods can be chained left to right: raw.strip().title().
.strip() drops spaces; .rstrip("!") drops trailing !. Chain them to fix Tobi’s shouting:
SALE
Sale
The original string is never changed. Each method hands back a new one.
What does this print?
a) MOIN b) moin c) moin
Predict first. Pick a letter, then I reveal the answer.
" MOIN ".strip().lower()b) moin: .strip() removes the outer spaces, then .lower() lowercases the result. Chained methods run left to right, each acting on the previous one’s output.
moin
Open the exercise (scan the QR or type the link):
python.tobiasvlcek.com/notebooks/ex_02_c/
First predict what happens, then run it.
A practice board review. Fifteen minutes, before the lab, ungraded. Same format as the five real checkpoints, so that nothing is new next week when it counts.
Menu → Download → Download Python code → upload the .py to the “Checkpoint 0” assignment on Moodle. Nothing is graded today: the point is that download and upload are muscle memory by Session III.
Next week this exact routine is Checkpoint 1: 40 minutes, 12 points, Sessions I–II. Today you get to make every mistake for free.
while loopDownload your .py before you leave. Closing the tab without downloading loses your work, and downloading is exactly how you hand in the checkpoints.
if / elif / else run the first true branch: test the strictest condition firstfor repeats over every item (accumulator: start at 0, add each); while repeats until its condition flips, and something inside must move it there.strip(), .title(), .upper(), .rstrip("!")) return a cleaned copy, and chain left to rightNext time — Episode 3 starts with Checkpoint 1: 40 minutes, no AI, everything from Episodes 1–2, so keep this notebook and the last one close. Then: Tobi has pasted the same receipt code 14 times, and one small change now takes him an afternoon. We bring in functions to the rescue.
Nothing new here, but these are still great books to start with!
For more, see the literature list of this course.
Lecture II - Control Structures for Your Code | Dr. Tobias Vlćek | Home