# The line starting with # is a comment — Python ignores it
print("Welcome to your food-delivery startup!")Welcome to your food-delivery startup!
Programming with Python
. . .
I really appreciate active participation and interaction!
. . .
Materials live in the KLU portal and are hosted at beyondsimulations.github.io/Introduction-to-Python.
.py file and upload it to Moodle. . .
The weekly lab exercises rehearse exactly this routine. Do them, and the checkpoints will feel familiar.
. . .
Learning the basics without AI first is what lets you judge AI output later.
uv, the Zed editor)This semester you are founding a campus food-delivery startup. Today it gets a name, a menu, and its first revenue calculation.
. . .
(Your co-founder Kevin has already spent the marketing budget on stickers.)
. . .
Today your startup’s first program does three small things: record the founding data, do one calculation, and print a summary.
print()print() is a function: you hand it something, it shows it on screen.
# The line starting with # is a comment — Python ignores it
print("Welcome to your food-delivery startup!")Welcome to your food-delivery startup!
=: name on the left, value on the rightcompany_founded = 2026 # store a whole number under a name
print(company_founded)2026
Store the facts of the new company, then use them by name:
company_founded = 2026
first_employee = "Kevin"
sticker_budget = 300 # what's left after Kevin's spending spree
print(first_employee)
print(sticker_budget)Kevin
300
_budget and Budget are two different namesfor, if, def, …). . .
Question — we solve this together, out loud: Which of these are valid variable names?
sticker_budget, 1st_employee, firstEmployee, company-name, _kevin
Every value has a type, which decides what you can do with the value:
str — text, in quotes: "Kevin", "Falafel Wrap"int — whole numbers: 2026, 300float — decimal numbers: 9.99, 0.15bool — truth values: True, Falsetype()type() tells you the type of any value, and it’s priceless when a bug surprises you:
print(type(2026)) # int
print(type("Kevin")) # str
print(type(9.99)) # float<class 'int'>
<class 'str'>
<class 'float'>
Kevin typed the price with quotes. What does this print?
print(type("9.99"))a) <class 'float'> b) <class 'int'> c) <class 'str'>
. . .
Predict first. Commit to an answer before the next slide.
type("9.99")c) str — the quotes make it text, however numeric it looks. Kevin’s “price” can’t be multiplied until it is converted to a number.
print(type("9.99"))<class 'str'>
Kevin’s grand plan: sell everything for 9.99. To see whether that survives contact with arithmetic, we need Python’s operators.
# margin = price - cost
print(9.99 - 4.20)5.79
print(9.99 + 1.50) # addition
print(9.99 - 4.20) # subtraction
print(9.99 * 3) # multiplication
print(300 / 8) # division — always gives a float11.49
5.79
29.97
37.5
// and %: how many fit, what’s left// floor division: how many whole times something fits% modulo: the remainder left over# The 300 EUR budget, boxes at 7 EUR each
print(300 // 7) # whole boxes we can buy
print(300 % 7) # EUR left over
print(10 // 2.5) # 4.0 — floor division on floats floors, but returns a float42
6
4.0
* and / happen before + and -. Parentheses override that.
print(2 + 3 * 4) # 14, not 20
print((2 + 3) * 4) # 2014
20
Kevin buys 12 boxes at 25 EUR from the 300 EUR budget. What prints?
print(300 - 12 * 25)a) 0 b) 7200 c) Error
. . .
Predict first, then turn the page.
300 - 12 * 25a) 0 — 12 * 25 = 300 happens first, so the budget is wiped out. Reading left to right would give 7200, but Python follows precedence, not reading order.
print(300 - 12 * 25)0
int + int stays an int; / always produces a floatint and a float gives a floatmargin = 9.99 - 4.20
print(margin)
print(type(margin))5.79
<class 'float'>
round(): clean moneyDivision can leave a long tail of decimals. round(value, 2) keeps two. Cents.
# Split a 10 EUR order three ways
print(10 / 3) # 3.3333333333333335 — ugly
print(round(10 / 3, 2)) # 3.33 — a proper amount3.3333333333333335
3.33
A string is text in quotes. Single or double quotes both work, just be consistent.
item = "Miso Ramen"
print(item)
print('Kevin shouts "9.99!"') # mix quotes to include a quote insideMiso Ramen
Kevin shouts "9.99!"
You can glue strings with +, but numbers must be converted first, and it gets clumsy fast:
qty = 2
item = "Miso Ramen"
total = 23.00
print(str(qty) + "x " + item + ": " + str(total) + " EUR")2x Miso Ramen: 23.0 EUR
. . .
(str(...) turns a value into text, which is clumsy. We’re about to see the better way.) Forget one str() and Python raises a TypeError.
Put an f before the quote and write values in { }, and Python fills them in:
qty = 2
item = "Miso Ramen"
total = 23.00
print(f"{qty}x {item}: {total} EUR")2x Miso Ramen: 23.0 EUR
. . .
No str(), no + — just the sentence you want.
:.2fInside the braces, :.2f forces two decimals, exactly what a receipt needs:
total = 23.00
print(f"{total} EUR") # 23.0 EUR — one decimal, looks broken on a receipt
print(f"{total:.2f} EUR") # 23.00 EUR — a proper price23.0 EUR
23.00 EUR
. . .
Python stores 23.00 as the number 23.0. Only you know it’s money, and :.2f says so.
\n\n inside a string starts a new line: one string, several lines.
print(f"Falafel Wrap: 6.90 EUR\nPad Thai: 8.90 EUR")Falafel Wrap: 6.90 EUR
Pad Thai: 8.90 EUR
What does each line print?
print(f"{2 * 3}")
print("2 * 3")a) 6 and 6 b) 6 and 2 * 3 c) 2 * 3 and 2 * 3
. . .
Predict first, then reveal.
f"{2 * 3}" vs "2 * 3"b) 6 and 2 * 3 — the f-string evaluates what’s in the braces; plain quotes keep the text literal. The f and the { } are what do the work.
print(f"{2 * 3}")
print("2 * 3")6
2 * 3
. . .
Download your .py before you leave. Closing the tab without downloading loses your work, and downloading is exactly how you hand in the checkpoints.
str, int, float, bool)* and / before + and -; round(x, 2) for money{value:.2f} turn numbers into clean receipt lines. . .
Next time — Episode 2: the city bans delivery after 22:00, and Kevin suggests “we just deliver yesterday’s orders.” We’ll need conditionals and loops to survive it.
. . .
Think Python is a great book to start with and is free online. Schrödinger programmiert Python is a playful German-language alternative with lots of examples.
. . .
For more, see the literature list of this course.