Skip to content

Commit dc8dd67

Browse files
Improved structure
1 parent 119a1ae commit dc8dd67

116 files changed

Lines changed: 2640 additions & 1355 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎_repo-md/general/cheatsheet.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ prices = {"Mate": 3.50, "Spezi": 3.20}
232232
print({k: round(v * 0.9, 2) for k, v in prices.items()}) # {'Mate': 3.15, 'Spezi': 2.88}
233233
```
234234

235-
Part I has no files, so data ships inside the code: `text.splitlines()` gives one string per line, `line.split(";")` splits a line at the separator.
236-
237235
## Session V: Errors & Debugging
238236

239237
### Reading a traceback, and the big five

‎_repo-md/lectures/lec_01_introduction.md‎

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,10 @@ a\) `Error` b) `300` c) `250`
197197

198198
. . .
199199

200-
<span class="question">Predict first</span>. Pick a letter, then I reveal the answer.
200+
<span class="question">Predict</span>. Pick a letter, then I reveal the answer.
201201

202202
## Answer: reassigning a name
203203

204-
**c) `250`**: the right side is computed first (`300 - 50`), then the name is pointed at the new value. A name always shows its *latest* value.
205-
206204
``` python
207205
sticker_budget = 300
208206
sticker_budget = sticker_budget - 50
@@ -211,6 +209,10 @@ print(sticker_budget)
211209

212210
250
213211

212+
. . .
213+
214+
**c) `250`**: the right side is computed first (`300 - 50`), then the name is pointed at the new value. A name always shows its *latest* value.
215+
214216
## Naming rules
215217

216218
- Must start with a **letter** or an underscore `_`
@@ -234,7 +236,7 @@ Scan the QR or type the link:
234236

235237
<img src="assets/qr/ex_01_a.png" width="280" />
236238

237-
First **predict** what happens, then run it.
239+
**Any questions?** Let me know!
238240

239241
## Four basic types
240242

@@ -271,18 +273,20 @@ a\) `<class 'float'>` b) `<class 'int'>` c) `<class 'str'>`
271273

272274
. . .
273275

274-
<span class="question">Predict first</span>. Pick a letter, then I reveal the answer.
276+
<span class="question">Predict</span>. Pick a letter, then I reveal the answer.
275277

276278
## Answer: `type("9.99")`
277279

278-
**c) `str`**: the quotes make it text, however numeric it looks. Tobi's "price" can't be multiplied until it is converted to a number.
279-
280280
``` python
281281
print(type("9.99"))
282282
```
283283

284284
<class 'str'>
285285

286+
. . .
287+
288+
**c) `str`**: the quotes make it text, however numeric it looks. Tobi's "price" can't be multiplied until it is converted to a number.
289+
286290
# Your turn: 5-10 minutes
287291

288292
## Open the exercise
@@ -293,7 +297,7 @@ Scan the QR or type the link:
293297

294298
<img src="assets/qr/ex_01_b.png" width="280" />
295299

296-
First **predict** what happens, then run it.
300+
**Any questions?** Let me know!
297301

298302
# <span class="flow">Numbers & Arithmetic</span>
299303

@@ -362,18 +366,20 @@ a\) `0` b) `7200` c) `Error`
362366

363367
. . .
364368

365-
<span class="question">Predict first</span>. Pick a letter, then I reveal the answer.
369+
<span class="question">Predict</span>. Pick a letter, then I reveal the answer.
366370

367371
## Answer: `300 - 12 * 25`
368372

369-
**a) `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.
370-
371373
``` python
372374
print(300 - 12 * 25)
373375
```
374376

375377
0
376378

379+
. . .
380+
381+
**a) `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.
382+
377383
## Predict: splitting a 10 EUR order
378384

379385
Two friends split a 10 EUR order. What prints?
@@ -386,18 +392,20 @@ a\) `5.0` b) `5` c) `Error`
386392

387393
. . .
388394

389-
<span class="question">Predict first</span>. Pick a letter, then I reveal the answer.
395+
<span class="question">Predict</span>. Pick a letter, then I reveal the answer.
390396

391397
## Answer: `10 / 2`
392398

393-
**a) `5.0`**: `/` always returns a `float`, even when the division comes out even. For a whole number, use `//`.
394-
395399
``` python
396400
print(10 / 2)
397401
```
398402

399403
5.0
400404

405+
. . .
406+
407+
**a) `5.0`**: `/` always returns a `float`, even when the division comes out even. For a whole number, use `//`.
408+
401409
## Whole numbers vs decimals
402410

403411
- `int` + `int` stays an `int`; `/` **always** produces a `float`
@@ -436,7 +444,7 @@ Scan the QR or type the link:
436444

437445
<img src="assets/qr/ex_01_c.png" width="280" />
438446

439-
First **predict** what happens, then run it.
447+
**Any questions?** Let me know!
440448

441449
# <span class="flow">Strings & f-strings</span>
442450

@@ -483,18 +491,20 @@ a\) `Error` b) `34` c) `7`
483491

484492
. . .
485493

486-
<span class="question">Predict first</span>. Pick a letter, then I reveal the answer.
494+
<span class="question">Predict</span>. Pick a letter, then I reveal the answer.
487495

488496
## Answer: `"3" + "4"`
489497

490-
**b) `34`**: with quotes, these are strings, and `+` on strings glues them together. To add numbers, drop the quotes (or convert with `int()`).
491-
492498
``` python
493499
print("3" + "4")
494500
```
495501

496502
34
497503

504+
. . .
505+
506+
**b) `34`**: with quotes, these are strings, and `+` on strings glues them together. To add numbers, drop the quotes (or convert with `int()`).
507+
498508
## f-strings: the clean way
499509

500510
Put an `f` before the quote and write values in `{ }`, and Python fills them in:
@@ -522,7 +532,7 @@ Scan the QR or type the link:
522532

523533
<img src="assets/qr/ex_01_d.png" width="280" />
524534

525-
First **predict** what happens, then run it.
535+
**Any questions?** Let me know!
526536

527537
## Formatting money with `:.2f`
528538

@@ -565,12 +575,10 @@ a\) `6` and `6` b) `6` and `2 * 3` c) `2 * 3` and `2 * 3`
565575

566576
. . .
567577

568-
<span class="question">Predict first</span>. Pick a letter, then I reveal the answer.
578+
<span class="question">Predict</span>. Pick a letter, then I reveal the answer.
569579

570580
## Answer: `f"{2 * 3}"` vs `"2 * 3"`
571581

572-
**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.
573-
574582
``` python
575583
print(f"{2 * 3}")
576584
print("2 * 3")
@@ -579,6 +587,10 @@ print("2 * 3")
579587
6
580588
2 * 3
581589

590+
. . .
591+
592+
**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.
593+
582594
# Your turn: 5-10 minutes
583595

584596
## Open the exercise
@@ -589,7 +601,7 @@ Scan the QR or type the link:
589601

590602
<img src="assets/qr/ex_01_e.png" width="280" />
591603

592-
First **predict** what happens, then run it.
604+
**Any questions?** Let me know!
593605

594606
# <span class="flow">To the Lab</span>
595607

0 commit comments

Comments
 (0)