From 2ebbac5e1ff2eb61927f94eadbe6da1f2463bece Mon Sep 17 00:00:00 2001 From: ckean02 Date: Mon, 10 Feb 2025 13:56:43 +0000 Subject: [PATCH] HW --- conditionals.ipynb | 451 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 389 insertions(+), 62 deletions(-) diff --git a/conditionals.ipynb b/conditionals.ipynb index 5c1392a..3e8a87b 100644 --- a/conditionals.ipynb +++ b/conditionals.ipynb @@ -41,9 +41,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Agamemnon\n", + "Menelaus\n", + "Ajax\n", + "Odysseus\n", + "Achilles\n", + "Achilles, you're the best!\n", + "Patroclus\n" + ] + } + ], "source": [ "achaeans = [\"Agamemnon\", \"Menelaus\", \"Ajax\", \"Odysseus\", \"Achilles\", \"Patroclus\"]\n", "\n", @@ -63,9 +77,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You're probably telling the truth, Agamemnon.\n", + "You're probably telling the truth, Menelaus.\n", + "You're probably telling the truth, Ajax.\n", + "I dunno if I buy that, Odysseus.\n", + "You're probably telling the truth, Achilles.\n", + "You're probably telling the truth, Patroclus.\n" + ] + } + ], "source": [ "for leader in achaeans:\n", " if leader != \"Odysseus\":\n", @@ -83,9 +110,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It's true!\n", + "But I provide a fallback!\n" + ] + } + ], "source": [ "if True:\n", " print(\"It's true!\")\n", @@ -107,9 +143,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "odysseus = \"Odysseus\"\n", "achilles = \"Achilles\"\n", @@ -119,18 +166,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "achilles != odysseus" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "achilles == odysseus" ] @@ -144,9 +213,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "achilles.lower() == \"Achilles\"" ] @@ -169,9 +249,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_achaeans = 200_000\n", "number_of_trojans = 100_000\n", @@ -181,36 +272,80 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_achaeans >= number_of_trojans" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_achaeans < number_of_trojans" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_trojans == number_of_achaeans" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_trojans * 2 == number_of_achaeans" ] @@ -226,9 +361,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_gods = 12\n", "\n", @@ -237,27 +383,60 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_gods > number_of_trojans or number_of_trojans < number_of_achaeans" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_trojans > number_of_achaeans and number_of_trojans > number_of_gods" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number_of_trojans > number_of_achaeans or number_of_trojans > number_of_gods" ] @@ -273,18 +452,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"Achilles\" in achaeans" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 103, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"Hector\" in achaeans" ] @@ -302,9 +503,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Andromache, you do not deserve what's about to happen to you and your family.\n" + ] + } + ], "source": [ "trojans = [\"Priam\", \"Hector\", \"Paris\", \"Aeneas\", \"Cassandra\", \"Hecuba\", \"Andromache\"]\n", "\n", @@ -329,9 +538,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Andromache, you do not deserve what's about to happen to you and your family.\n", + "Paris! So that's where my leopard-print suit went!\n" + ] + } + ], "source": [ "if \"Achilles\" in trojans:\n", " print(\"Whoa, Achilles, what are you doing there!?\")\n", @@ -356,11 +574,120 @@ "5. Collect all of the dialogue spoken by Socrates in a single string (recall multiline strings with `\"\"\"`). Do likewise for Phaedrus.\n", "6. Use `len()` and a comparison operator to confirm that Socrates speaks more than Phaedrus." ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('Socrates', 'Phaedrus', 'Theuth', 'Ibis', 'Thamus', 'Ammon')\n" + ] + } + ], + "source": [ + "names = \"Socrates\", \"Phaedrus\", \"Theuth\", \"Ibis\", \"Thamus\", \"Ammon\"\n", + "print(names)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You are just a lowly mortal Socrates.\n", + "You are just a lowly mortal Phaedrus.\n", + "Oh great Greek god!, Theuth.\n", + "Oh great Greek god!, Ibis.\n", + "Oh great Greek god!, Thamus.\n", + "Oh great Greek god!, Ammon.\n" + ] + } + ], + "source": [ + "mortals = \"Socrates\", \"Phaedrus\"\n", + "gods = \"Theuth\", \"Ibis\", \"Thamus\", \"Ammon\"\n", + "\n", + "for name in names:\n", + " if name in gods:\n", + " print(f\"Oh great Greek god!, {name}.\")\n", + " else:\n", + " print(f\"You are just a lowly mortal {name}.\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of mortals: 2\n", + "Number of gods: 4\n" + ] + } + ], + "source": [ + "print(f\"Number of mortals: {len(mortals)}\")\n", + "print(f\"Number of gods: {len(gods)}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [], + "source": [ + "socrates_dialogue = \"\"\"Anyway [ge], Ive heard a saying among our ancestors, but they [alone] know its truth. But if we ourselves uncover it, would human conjectures still matter to us?\n", + "\n", + "Well then, I heard that at Naucratis, in Egypt, there was some one of the ancient gods, who also has a sacred bird which they call “Ibis” — but the name of this divinity is Theuth. He was the first to discover arithmetic [arithmon] and calculation [logismon], geometry and astronomy, even backgammon and dice-playing, and especially letters.\n", + "Now at that time the king of all Egypt was Thamus in the great city of the upper region, which the Greeks call “Egyptian Thebes” — and they call the god Ammon.\n", + "And Theuth came to his palace to show him his skills [tas technas], and he said it was necessary to distribute them among the other Egyptians — but Thamus asked what the use [ōphelian] of each skill was. And while Theuth went through them, Thamus said whether each one seemed fine or not to him, censuring some and praising others.\n", + "It is said, on the one hand, that Thamus said many such things on both sides [praise and blame] about each skill [peri hekastēs technēs] when Theuth was explaining them — the account [logos] of them would take a while to go through. But when it came to letters, Theuth said, “This invention, O king, will make the Egyptians wiser and more capable of remembering: for I have discovered a drug [pharmakon] for memory and wisdom.” And Thamus replied, “O most-skilled [technikōtate] Theuth, one person can fashion elements of a skill [ta technēs], but it’s up to someone else to judge what share of blame and usefulness it has for those who are going to use it. And now you, since you are the father of letters, because of your partiality, say that they have a capability opposite to what they really do. For this [invention] will yield forgetfulness in the souls of those who have learned it, and negligence with regard to their memories. Because they will remember through their trust in writing — foreign markings from outside — rather than from within themselves.\n", + "“So you have not discovered a drug for memory but for reminding. And you furnish your learners with what seems like wisdom, not true wisdom. For they will become hearers-of-many-things [polyēkooi] without instruction, and they will seem to be much-learned [polygnōmones] to you, but they will for the most part be unlearned [agnōmones], and they will make difficult company, since they will have become wise-seemers instead of wise people.”\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [], + "source": [ + "phaedrus_dialogue = \"\"\"You’re talking nonsense — but tell me what you said that you heard.\n", + "\n", + "O Socrates, you easily make up stories [logous] about Egypt and anywhere you want.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Socrates speaks wayyyyy more than Phaedrus: True\n" + ] + } + ], + "source": [ + "print(f\"Socrates speaks wayyyyy more than Phaedrus: {len(socrates_dialogue) > len(phaedrus_dialogue)}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -374,7 +701,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.7" + "version": "3.12.1" } }, "nbformat": 4,