Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions 2-basic-operations/11_titanic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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]}')"
]
},
{
Expand All @@ -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}')"
]
}
],
Expand All @@ -170,7 +211,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down