You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit dc8dd67
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: _repo-md/lectures/lec_01_introduction.md
+35-23Lines changed: 35 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -197,12 +197,10 @@ a\) `Error` b) `300` c) `250`
197
197
198
198
. . .
199
199
200
-
<spanclass="question">Predict first</span>. Pick a letter, then I reveal the answer.
200
+
<spanclass="question">Predict</span>. Pick a letter, then I reveal the answer.
201
201
202
202
## Answer: reassigning a name
203
203
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
-
206
204
```python
207
205
sticker_budget =300
208
206
sticker_budget = sticker_budget -50
@@ -211,6 +209,10 @@ print(sticker_budget)
211
209
212
210
250
213
211
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
+
214
216
## Naming rules
215
217
216
218
- Must start with a **letter** or an underscore `_`
@@ -234,7 +236,7 @@ Scan the QR or type the link:
234
236
235
237
<imgsrc="assets/qr/ex_01_a.png"width="280" />
236
238
237
-
First **predict**what happens, then run it.
239
+
**Any questions?**Let me know!
238
240
239
241
## Four basic types
240
242
@@ -271,18 +273,20 @@ a\) `<class 'float'>` b) `<class 'int'>` c) `<class 'str'>`
271
273
272
274
. . .
273
275
274
-
<spanclass="question">Predict first</span>. Pick a letter, then I reveal the answer.
276
+
<spanclass="question">Predict</span>. Pick a letter, then I reveal the answer.
275
277
276
278
## Answer: `type("9.99")`
277
279
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
-
280
280
```python
281
281
print(type("9.99"))
282
282
```
283
283
284
284
<class 'str'>
285
285
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
+
286
290
# Your turn: 5-10 minutes
287
291
288
292
## Open the exercise
@@ -293,7 +297,7 @@ Scan the QR or type the link:
293
297
294
298
<imgsrc="assets/qr/ex_01_b.png"width="280" />
295
299
296
-
First **predict**what happens, then run it.
300
+
**Any questions?**Let me know!
297
301
298
302
# <spanclass="flow">Numbers & Arithmetic</span>
299
303
@@ -362,18 +366,20 @@ a\) `0` b) `7200` c) `Error`
362
366
363
367
. . .
364
368
365
-
<spanclass="question">Predict first</span>. Pick a letter, then I reveal the answer.
369
+
<spanclass="question">Predict</span>. Pick a letter, then I reveal the answer.
366
370
367
371
## Answer: `300 - 12 * 25`
368
372
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
-
371
373
```python
372
374
print(300-12*25)
373
375
```
374
376
375
377
0
376
378
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
+
377
383
## Predict: splitting a 10 EUR order
378
384
379
385
Two friends split a 10 EUR order. What prints?
@@ -386,18 +392,20 @@ a\) `5.0` b) `5` c) `Error`
386
392
387
393
. . .
388
394
389
-
<spanclass="question">Predict first</span>. Pick a letter, then I reveal the answer.
395
+
<spanclass="question">Predict</span>. Pick a letter, then I reveal the answer.
390
396
391
397
## Answer: `10 / 2`
392
398
393
-
**a) `5.0`**: `/` always returns a `float`, even when the division comes out even. For a whole number, use `//`.
394
-
395
399
```python
396
400
print(10/2)
397
401
```
398
402
399
403
5.0
400
404
405
+
. . .
406
+
407
+
**a) `5.0`**: `/` always returns a `float`, even when the division comes out even. For a whole number, use `//`.
408
+
401
409
## Whole numbers vs decimals
402
410
403
411
-`int` + `int` stays an `int`; `/`**always** produces a `float`
@@ -436,7 +444,7 @@ Scan the QR or type the link:
436
444
437
445
<imgsrc="assets/qr/ex_01_c.png"width="280" />
438
446
439
-
First **predict**what happens, then run it.
447
+
**Any questions?**Let me know!
440
448
441
449
# <spanclass="flow">Strings & f-strings</span>
442
450
@@ -483,18 +491,20 @@ a\) `Error` b) `34` c) `7`
483
491
484
492
. . .
485
493
486
-
<spanclass="question">Predict first</span>. Pick a letter, then I reveal the answer.
494
+
<spanclass="question">Predict</span>. Pick a letter, then I reveal the answer.
487
495
488
496
## Answer: `"3" + "4"`
489
497
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
-
492
498
```python
493
499
print("3"+"4")
494
500
```
495
501
496
502
34
497
503
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
+
498
508
## f-strings: the clean way
499
509
500
510
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:
522
532
523
533
<imgsrc="assets/qr/ex_01_d.png"width="280" />
524
534
525
-
First **predict**what happens, then run it.
535
+
**Any questions?**Let me know!
526
536
527
537
## Formatting money with `:.2f`
528
538
@@ -565,12 +575,10 @@ a\) `6` and `6` b) `6` and `2 * 3` c) `2 * 3` and `2 * 3`
565
575
566
576
. . .
567
577
568
-
<spanclass="question">Predict first</span>. Pick a letter, then I reveal the answer.
578
+
<spanclass="question">Predict</span>. Pick a letter, then I reveal the answer.
569
579
570
580
## Answer: `f"{2 * 3}"` vs `"2 * 3"`
571
581
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
-
574
582
```python
575
583
print(f"{2*3}")
576
584
print("2 * 3")
@@ -579,6 +587,10 @@ print("2 * 3")
579
587
6
580
588
2 * 3
581
589
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.
0 commit comments