|
16 | 16 | "cell_type": "code", |
17 | 17 | "execution_count": null, |
18 | 18 | "id": "b263fdce", |
19 | | - "metadata": {}, |
| 19 | + "metadata": { |
| 20 | + "scrolled": true |
| 21 | + }, |
20 | 22 | "outputs": [], |
21 | 23 | "source": [ |
22 | 24 | "import this" |
|
32 | 34 | "Also, by importing `this`, it actually executed some code (printing out the Zen of Python). This means Python knew where to find a module called `this` and executed it upon import." |
33 | 35 | ] |
34 | 36 | }, |
| 37 | + { |
| 38 | + "cell_type": "markdown", |
| 39 | + "id": "dea36f8c-3ec4-49e4-996c-46657360b45f", |
| 40 | + "metadata": {}, |
| 41 | + "source": [ |
| 42 | + "Let's try another easter egg, just for fun." |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "code", |
| 47 | + "execution_count": null, |
| 48 | + "id": "c4ef38cd-5dfc-496c-b4be-eac49eab1bed", |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [], |
| 51 | + "source": [] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "markdown", |
| 55 | + "id": "aa2aca2a-c965-41ac-8ae1-e339ed74041f", |
| 56 | + "metadata": {}, |
| 57 | + "source": [ |
| 58 | + "The goal of this notebook is to provide students with the skills needed to create resuable functions, objects, and python moduldes. \n", |
| 59 | + "\n", |
| 60 | + "By the end of this notebook the student will have the skills required to create a complex object in a seperate python script, import it's functionality into this notebook, and be able to work with it here." |
| 61 | + ] |
| 62 | + }, |
35 | 63 | { |
36 | 64 | "cell_type": "markdown", |
37 | 65 | "id": "ccff90ef", |
|
183 | 211 | "source": [ |
184 | 212 | "a=[1.0, 2.0, 3.5, 4.9]\n", |
185 | 213 | "print (f'{a=}')\n", |
186 | | - "b=a\n", |
| 214 | + "b = a\n", |
187 | 215 | "print (f'{b=}')\n", |
188 | 216 | "print ('_'*15)\n", |
189 | | - "b[2]=999\n", |
| 217 | + "b[2] = 999\n", |
190 | 218 | "print (f'{a=}')\n", |
191 | 219 | "print (f'{b=}')" |
192 | 220 | ] |
|
486 | 514 | "id": "a0ba121a", |
487 | 515 | "metadata": {}, |
488 | 516 | "outputs": [], |
489 | | - "source": [] |
| 517 | + "source": [ |
| 518 | + "# attrs" |
| 519 | + ] |
490 | 520 | }, |
491 | 521 | { |
492 | 522 | "cell_type": "code", |
493 | 523 | "execution_count": null, |
494 | 524 | "id": "efbd4d86", |
495 | 525 | "metadata": {}, |
496 | 526 | "outputs": [], |
497 | | - "source": [] |
| 527 | + "source": [ |
| 528 | + "# in a list" |
| 529 | + ] |
498 | 530 | }, |
499 | 531 | { |
500 | 532 | "cell_type": "code", |
501 | 533 | "execution_count": null, |
502 | 534 | "id": "b0a41016", |
503 | 535 | "metadata": {}, |
504 | 536 | "outputs": [], |
505 | | - "source": [] |
| 537 | + "source": [ |
| 538 | + "# attrs in list" |
| 539 | + ] |
506 | 540 | }, |
507 | 541 | { |
508 | 542 | "cell_type": "code", |
509 | 543 | "execution_count": null, |
510 | 544 | "id": "cde66e11", |
511 | 545 | "metadata": {}, |
512 | 546 | "outputs": [], |
513 | | - "source": [] |
| 547 | + "source": [ |
| 548 | + "# loop" |
| 549 | + ] |
514 | 550 | }, |
515 | 551 | { |
516 | 552 | "cell_type": "markdown", |
|
857 | 893 | "metadata": {}, |
858 | 894 | "outputs": [], |
859 | 895 | "source": [ |
860 | | - "rr.length = 100\n", |
861 | | - "rr.__dict__" |
| 896 | + "# what happens when we change the length?" |
862 | 897 | ] |
863 | 898 | }, |
864 | 899 | { |
|
932 | 967 | "source": [ |
933 | 968 | "### Test your skills!!!\n", |
934 | 969 | "\n", |
935 | | - "build a `Rectangle` class that includes an `area` and `perimiter_length` property method.\n" |
| 970 | + "build an even better `Rectangle` class that includes an `area` and `perimiter_length` property method.\n" |
936 | 971 | ] |
937 | 972 | }, |
938 | 973 | { |
|
1086 | 1121 | "metadata": {}, |
1087 | 1122 | "outputs": [], |
1088 | 1123 | "source": [ |
1089 | | - " print(rect)" |
| 1124 | + "print(rect)" |
1090 | 1125 | ] |
1091 | 1126 | }, |
1092 | 1127 | { |
|
1096 | 1131 | "source": [ |
1097 | 1132 | "We can even overload other operators like `__add__` which will control what happens when this object is added to another.\n", |
1098 | 1133 | "\n", |
1099 | | - "A complete list of which special methods and operators can be overloaded is found [here](https://docs.python.org/3.9/reference/datamodel.html#special-method-names)." |
| 1134 | + "A complete list of which special methods and operators can be overloaded is found [here](https://docs.python.org/3.9/reference/datamodel.html#special-method-names). \n", |
| 1135 | + "\n", |
| 1136 | + "A short list of standard operators for mathematical functions can be found [here](https://docs.python.org/3/library/operator.html)." |
1100 | 1137 | ] |
1101 | 1138 | }, |
1102 | 1139 | { |
|
1386 | 1423 | " err = abs(i1 - i0)\n", |
1387 | 1424 | " i0 = i1\n", |
1388 | 1425 | " \n", |
1389 | | - " print (f'my complicated function estimates sqrt as--> {i1}!')\n" |
| 1426 | + " print (f'my complicated function estimates sqrt as--> {i1}')\n" |
1390 | 1427 | ] |
1391 | 1428 | }, |
1392 | 1429 | { |
|
1556 | 1593 | "\n", |
1557 | 1594 | "Open the python file \"circle_module.py\" in an IDE or text editor and create a class called `Circle`. Inputs to circle should be a radius and ID. Include in the `Circle` class a way to the calculate area and the circumference. After building the class, try importing into this notebook and using it.\n", |
1558 | 1595 | "\n", |
1559 | | - "**Bonus exercise:** Find a way to make the `Circle` objects divisible and compare the difference in area between a 12\" and 16\" pizza.\n" |
| 1596 | + "**Bonus exercise:** Find a way to make the `Circle` objects divisible and compare the difference in area between a 12\" and 16\" pizza. \n", |
| 1597 | + "**Bonus exercise 2:** Add additonal functionality to compare the price per square inch of the two pizzas. Ian's pizza in Madison, WI lists sizes and prices on their website which could be used as a reference." |
1560 | 1598 | ] |
1561 | 1599 | }, |
1562 | 1600 | { |
|
1605 | 1643 | "display_name": "Python 3 (ipykernel)", |
1606 | 1644 | "language": "python", |
1607 | 1645 | "name": "python3" |
| 1646 | + }, |
| 1647 | + "language_info": { |
| 1648 | + "codemirror_mode": { |
| 1649 | + "name": "ipython", |
| 1650 | + "version": 3 |
| 1651 | + }, |
| 1652 | + "file_extension": ".py", |
| 1653 | + "mimetype": "text/x-python", |
| 1654 | + "name": "python", |
| 1655 | + "nbconvert_exporter": "python", |
| 1656 | + "pygments_lexer": "ipython3", |
| 1657 | + "version": "3.12.11" |
1608 | 1658 | } |
1609 | 1659 | }, |
1610 | 1660 | "nbformat": 4, |
|
0 commit comments