From 334790a425d0c136ef1287ea4cac84dc8f9fb066 Mon Sep 17 00:00:00 2001 From: Pawel-Pagacz <254937@student.pwr.edu.pl> Date: Wed, 23 Oct 2024 21:56:18 +0200 Subject: [PATCH 1/2] Add code so you don't have to imagine the solution anymore --- 2-basic-operations/11_titanic.ipynb | 51 ++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/2-basic-operations/11_titanic.ipynb b/2-basic-operations/11_titanic.ipynb index c3f9832..70a5bf5 100644 --- a/2-basic-operations/11_titanic.ipynb +++ b/2-basic-operations/11_titanic.ipynb @@ -132,9 +132,36 @@ "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Age of the youngest person: 0\n", + "Index of the youngest person: 44\n", + "Age of the oldest person: 70\n", + "Index of the youngest person: 32\n" + ] + } + ], "source": [ - "# You gotta figure this out!" + "(rows, cols) = passengers.shape\n", + "oldest = 0\n", + "youngest = 999\n", + "for i in range(rows):\n", + " temp = passengers[i][3]\n", + " if youngest <= temp:\n", + " youngest = youngest\n", + " if oldest <= temp:\n", + " oldest = temp\n", + " index_oldest = i\n", + " else:\n", + " youngest = temp\n", + " index_youngest = i\n", + "print(f'Age of the youngest person: {youngest}')\n", + "print(f'Index of the youngest person: {passengers[index_youngest][0]}')\n", + "print(f'Age of the oldest person: {oldest}')\n", + "print(f'Index of the youngest person: {passengers[index_oldest][0]}')" ] }, { @@ -148,9 +175,23 @@ "cell_type": "code", "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "22\n", + "The percent of folks who survived is: 0.44\n" + ] + } + ], "source": [ - "# You gotta figure this out. 💔" + "(rows, cols) = passengers.shape\n", + "survived = []\n", + "for i in range(rows):\n", + " (survived.append(passengers[i]) if passengers[i][1] == 1 else None)\n", + "print(len(survived))\n", + "print(f'The percent of folks who survived is: {len(survived)/rows}')" ] } ], @@ -170,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.10.11" } }, "nbformat": 4, From 5e5d6f81f251579eb37f0ae0e0940e16e5509a4d Mon Sep 17 00:00:00 2001 From: Pawel-Pagacz <141075199+Pawel-Pagacz@users.noreply.github.com> Date: Wed, 23 Oct 2024 22:10:26 +0200 Subject: [PATCH 2/2] Update 11_titanic.ipynb --- 2-basic-operations/11_titanic.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-basic-operations/11_titanic.ipynb b/2-basic-operations/11_titanic.ipynb index 70a5bf5..d6b14a9 100644 --- a/2-basic-operations/11_titanic.ipynb +++ b/2-basic-operations/11_titanic.ipynb @@ -140,7 +140,7 @@ "Age of the youngest person: 0\n", "Index of the youngest person: 44\n", "Age of the oldest person: 70\n", - "Index of the youngest person: 32\n" + "Index of the oldest person: 32\n" ] } ],