diff --git a/2-basic-operations/11_titanic.ipynb b/2-basic-operations/11_titanic.ipynb index c3f9832..d6b14a9 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 oldest 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,