|
21 | 21 | "Let’s do this now: click just below where it says “print (403.616”),\n", |
22 | 22 | "then Go to the “Run” menu and choose “Run Selected Cells”." |
23 | 23 | ], |
24 | | - "id": "69031fcb-8372-456e-890d-cfa2ae19a74c" |
| 24 | + "id": "b2dea3de-65e1-4308-ab5a-03fb05ac8f37" |
25 | 25 | }, |
26 | 26 | { |
27 | 27 | "cell_type": "code", |
|
51 | 51 | "Click in the next cell (where it says “103.5”) to select that cell. Then\n", |
52 | 52 | "hold down the Shift key while you press Enter." |
53 | 53 | ], |
54 | | - "id": "a2e68208-7c05-4768-9958-cbba3a0e5ec7" |
| 54 | + "id": "2341a1ce-385b-467c-8779-537ed6891974" |
55 | 55 | }, |
56 | 56 | { |
57 | 57 | "cell_type": "code", |
|
75 | 75 | "\n", |
76 | 76 | "Take a look at a *string literal*. Run each of the next two cells…" |
77 | 77 | ], |
78 | | - "id": "1836bb88-7a54-41b6-83b5-d9679c42449c" |
| 78 | + "id": "b3143937-e08a-496e-84d4-7da01663291f" |
79 | 79 | }, |
80 | 80 | { |
81 | 81 | "cell_type": "code", |
|
114 | 114 | "of the code-containing cells through this course, try to predict what\n", |
115 | 115 | "will happen first, and then run the code." |
116 | 116 | ], |
117 | | - "id": "ae1aebdb-e650-4ba5-8329-0a31239508d3" |
| 117 | + "id": "b57c8484-f4bd-4da7-85fb-fb35f5027bb2" |
118 | 118 | }, |
119 | 119 | { |
120 | 120 | "cell_type": "code", |
|
182 | 182 | "source": [ |
183 | 183 | "Besides the “classic” operators, there are some handy extras:" |
184 | 184 | ], |
185 | | - "id": "9a76b03b-0aae-4592-8dc6-a4a35a480def" |
| 185 | + "id": "f6053830-f7f8-4c67-854a-7c7e45248216" |
186 | 186 | }, |
187 | 187 | { |
188 | 188 | "cell_type": "code", |
|
202 | 202 | "returns the whole number part of the answer, just like when we learned\n", |
203 | 203 | "division in elementary school." |
204 | 204 | ], |
205 | | - "id": "84fec351-13c0-4691-bcbc-de6729932d18" |
| 205 | + "id": "8a7e2f79-be53-4be6-81c0-472b36763c95" |
206 | 206 | }, |
207 | 207 | { |
208 | 208 | "cell_type": "code", |
|
221 | 221 | "The `%` operator returns the remainder. This is also called “modulo”,\n", |
222 | 222 | "and the above would be pronounced “sixteen mod 3”." |
223 | 223 | ], |
224 | | - "id": "a4c909d7-88a8-4b66-b074-f86322b823c3" |
| 224 | + "id": "451a0b86-1e1c-4969-b38c-e5043465c197" |
225 | 225 | }, |
226 | 226 | { |
227 | 227 | "cell_type": "code", |
|
261 | 261 | "or they can be real numbers. Naturally, operators can be combined into\n", |
262 | 262 | "arbitrarily long *expressions*." |
263 | 263 | ], |
264 | | - "id": "e43bebad-7396-483b-a538-018b32395714" |
| 264 | + "id": "8018c55f-9072-4835-9157-efe4e34e8a28" |
265 | 265 | }, |
266 | 266 | { |
267 | 267 | "cell_type": "code", |
|
298 | 298 | "evaluated as 3+2 and yields 5. The exception is exponentiation: 2 \\*\\* 3\n", |
299 | 299 | "\\*\\* 4 is treated as 2 \\*\\* 81 and yeilds an annoyingly large number" |
300 | 300 | ], |
301 | | - "id": "c1a3a6c3-37a4-496c-993b-70976a7a62e2" |
| 301 | + "id": "a8098906-1cae-4c79-bc62-b6437b5b9d89" |
302 | 302 | }, |
303 | 303 | { |
304 | 304 | "cell_type": "code", |
|
332 | 332 | "to store data of some kind, and that place has a name. They behave in\n", |
333 | 333 | "Python just like you’d expect." |
334 | 334 | ], |
335 | | - "id": "9576a948-0ac7-45fd-8d57-6c0996ae0b36" |
| 335 | + "id": "45cfc510-35d0-4f7f-9e49-49c53c2471ef" |
336 | 336 | }, |
337 | 337 | { |
338 | 338 | "cell_type": "code", |
|
363 | 363 | "long as Python (or in our case, Jupyter) is running. Take a look -\n", |
364 | 364 | "answer is still there." |
365 | 365 | ], |
366 | | - "id": "af15c146-97fd-435b-aeb4-3feb1f1d35e0" |
| 366 | + "id": "9e98f7a7-29ef-4c5a-961e-ea82c63acab5" |
367 | 367 | }, |
368 | 368 | { |
369 | 369 | "cell_type": "code", |
|
381 | 381 | "source": [ |
382 | 382 | "The value stored in a variable can change. It can even change type:" |
383 | 383 | ], |
384 | | - "id": "8b0dc5c6-e2cd-4209-ad99-17a27deba452" |
| 384 | + "id": "f73be873-286b-4f05-b96f-b89405a9a662" |
385 | 385 | }, |
386 | 386 | { |
387 | 387 | "cell_type": "code", |
|
404 | 404 | "We can declare many variables, and we can “do things” with them just\n", |
405 | 405 | "like we can when we type in numbers or strings." |
406 | 406 | ], |
407 | | - "id": "924bbc58-a104-45d4-bad4-4785ddbe92db" |
| 407 | + "id": "a131a83b-ed34-4712-b623-68f3175d8226" |
408 | 408 | }, |
409 | 409 | { |
410 | 410 | "cell_type": "code", |
|
429 | 429 | "We can use variables to change the *order of operations*. Let’s see the\n", |
430 | 430 | "average price of two people’s meals:" |
431 | 431 | ], |
432 | | - "id": "56a5a40b-8010-4259-acb0-db185cd530bb" |
| 432 | + "id": "e7422fea-b9dc-445d-9116-61c3ad5b0642" |
433 | 433 | }, |
434 | 434 | { |
435 | 435 | "cell_type": "code", |
|
449 | 449 | "source": [ |
450 | 450 | "That’s the right answer. If we hadn’t done that, we would have gotten" |
451 | 451 | ], |
452 | | - "id": "c2f0b07f-b6eb-4e3b-b3a0-0b66d7af5956" |
| 452 | + "id": "22428be3-0600-4999-aa6c-e08e35ea9958" |
453 | 453 | }, |
454 | 454 | { |
455 | 455 | "cell_type": "code", |
|
490 | 490 | "*type* they are (integer, real number, or string) and what their “value”\n", |
491 | 491 | "is. We can even interrogate a variable as see what type it is:" |
492 | 492 | ], |
493 | | - "id": "cf3734b2-55eb-4abd-8c1f-3776ea5313e2" |
| 493 | + "id": "b4d230fa-b73c-404e-926a-ad2be68390bd" |
494 | 494 | }, |
495 | 495 | { |
496 | 496 | "cell_type": "code", |
|
538 | 538 | "The type of a variable matters. Let’s create a variable with an integer\n", |
539 | 539 | "in it and another with a string. Then let’s do some math:" |
540 | 540 | ], |
541 | | - "id": "576ce253-a0df-4884-a245-69ba9e96ea9c" |
| 541 | + "id": "9b381d8d-cbad-4a14-a434-0f513e4c1f7c" |
542 | 542 | }, |
543 | 543 | { |
544 | 544 | "cell_type": "code", |
|
565 | 565 | "functions convert their arguments to floating-point and to integer\n", |
566 | 566 | "numbers, respectively." |
567 | 567 | ], |
568 | | - "id": "b1d94bf0-e305-4e10-8111-4f30913e6d47" |
| 568 | + "id": "28468e75-8a8a-4c3e-a80f-14221ab9c7e7" |
569 | 569 | }, |
570 | 570 | { |
571 | 571 | "cell_type": "code", |
|
604 | 604 | "programming languages will let us split an expression anywhere we want,\n", |
605 | 605 | "such as:" |
606 | 606 | ], |
607 | | - "id": "87cefeb2-935b-4773-9dde-63f765c917d7" |
| 607 | + "id": "1f1722d2-5e75-4a33-95d9-16fa947bd733" |
608 | 608 | }, |
609 | 609 | { |
610 | 610 | "cell_type": "code", |
|
628 | 628 | "a backslash, by the way, and **cannot** be the forward slash like we use\n", |
629 | 629 | "for division." |
630 | 630 | ], |
631 | | - "id": "bb25bb15-500d-44dc-a13a-f9dbbd14bd6c" |
| 631 | + "id": "d3eee19c-6a9e-407a-84c1-2192960c7166" |
632 | 632 | }, |
633 | 633 | { |
634 | 634 | "cell_type": "code", |
|
660 | 660 | "one, make sure you figure out what happened before you go. I know, we’re\n", |
661 | 661 | "professionals, I shouldn’t have to say that…" |
662 | 662 | ], |
663 | | - "id": "72b20305-aba7-46f1-8057-e03566c49bbd" |
| 663 | + "id": "f54b9890-c09e-4184-b8f0-5ee81b184c76" |
664 | 664 | }, |
665 | 665 | { |
666 | 666 | "cell_type": "code", |
|
691 | 691 | "And these can be any kind of characters - the English alphabet, the\n", |
692 | 692 | "Hungarian alphabet, hiragana… it doesn’t matter." |
693 | 693 | ], |
694 | | - "id": "5fbb0218-b7db-48ac-82b0-184357cd3a14" |
| 694 | + "id": "d38b39d2-65f5-4431-8e46-3f52483a7eae" |
695 | 695 | }, |
696 | 696 | { |
697 | 697 | "cell_type": "code", |
|
713 | 713 | "Python lets you use either one. You *do* have to be consistent in each\n", |
714 | 714 | "string, but it can vary from one string to the next:" |
715 | 715 | ], |
716 | | - "id": "acb074e3-0319-4dab-8e4c-9aac22d46b35" |
| 716 | + "id": "a5c1d887-0ec9-4976-9f98-61aca566b838" |
717 | 717 | }, |
718 | 718 | { |
719 | 719 | "cell_type": "code", |
|
734 | 734 | "Because we can use either type of quotation mark, we can exploit that to\n", |
735 | 735 | "let us put quotation marks into strings:" |
736 | 736 | ], |
737 | | - "id": "6dd517ca-d4f3-4aab-bfd8-be0f4fe162ef" |
| 737 | + "id": "94ba0c9a-5908-4620-8cdb-d6afafca6189" |
738 | 738 | }, |
739 | 739 | { |
740 | 740 | "cell_type": "code", |
|
768 | 768 | "quotation mark. In fact, we can quote any character with it if we need\n", |
769 | 769 | "to." |
770 | 770 | ], |
771 | | - "id": "c21f9b33-7c75-4439-a7bb-55736e9f305b" |
| 771 | + "id": "ea8674ea-c52d-409e-8ba1-9d40ef9cf29f" |
772 | 772 | }, |
773 | 773 | { |
774 | 774 | "cell_type": "code", |
|
809 | 809 | "that is several lines long. The “triple quote” is a way to do it. You\n", |
810 | 810 | "have to use three double-quotes in a row:" |
811 | 811 | ], |
812 | | - "id": "1ee3f610-e530-42ec-a92f-582d3f32474a" |
| 812 | + "id": "c13b0a69-cfb2-4030-9f55-1b5f077b6856" |
813 | 813 | }, |
814 | 814 | { |
815 | 815 | "cell_type": "code", |
|
831 | 831 | "Triple quotes are also an easier way to embed mixed kinds of quotation\n", |
832 | 832 | "marks into strings:" |
833 | 833 | ], |
834 | | - "id": "efdf7373-50e6-4c1e-af37-2038ca6b5192" |
| 834 | + "id": "f6b28b2f-ec56-4c2d-97e3-3c5bdebcb5c4" |
835 | 835 | }, |
836 | 836 | { |
837 | 837 | "cell_type": "code", |
|
865 | 865 | "to different inputs. That’s about to change. In the next section we’ll\n", |
866 | 866 | "look at the `if` statement and how to use it." |
867 | 867 | ], |
868 | | - "id": "4d19770b-2fe5-4cbc-9d45-b2f3bdf74422" |
| 868 | + "id": "b219c64a-dd61-4f6c-8393-064de2b6a41b" |
869 | 869 | } |
870 | 870 | ], |
871 | 871 | "nbformat": 4, |
|
0 commit comments