Skip to content
Open
Show file tree
Hide file tree
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
129 changes: 110 additions & 19 deletions 1.-Python/1.-Snail-and-Well/snail-and-well.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": []
"source": [
"well_height = 125\n",
"daily_distance = 30\n",
"nightly_distance = -20\n",
"snail_position = 0"
]
},
{
"cell_type": "markdown",
Expand All @@ -44,10 +49,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": []
"source": [
"days = 0"
]
},
{
"cell_type": "markdown",
Expand All @@ -58,10 +65,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": []
"source": [
"while snail_position < well_height:\n",
" snail_position = snail_position + daily_distance + nightly_distance\n",
" days += 1"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +83,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Days taken for the snail to escape the well: 13\n"
]
}
],
"source": [
"print(\"Days taken for the snail to escape the well:\", days)"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +117,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Days taken for the snail to escape the well: 6\n"
]
}
],
"source": [
"well_height = 125\n",
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"nightly_distance = -20\n",
"snail_position = 0\n",
"\n",
"days = 0\n",
"\n",
"while snail_position < well_height:\n",
" snail_position = snail_position + advance_cm[days] + nightly_distance\n",
" days += 1\n",
" \n",
"print(\"Days taken for the snail to escape the well:\", days)"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +153,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Maximum displacement in one day: 57\n",
"Minimum displacement in one day: 1\n"
]
}
],
"source": [
"def displacement(day):\n",
" return(advance_cm[day] + nightly_distance)\n",
"\n",
"displacement_list = []\n",
"\n",
"for i in range(6):\n",
" displacement_list.append(displacement(i))\n",
"\n",
"print(\"Maximum displacement in one day:\", max(displacement_list))\n",
"\n",
"print(\"Minimum displacement in one day:\", min(displacement_list))"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +188,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average progress: 21.666666666666668\n"
]
}
],
"source": [
"print(\"Average progress:\", sum(displacement_list)/len(displacement_list))"
]
},
{
"cell_type": "markdown",
Expand All @@ -137,6 +210,24 @@
"#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night."
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Standard deviation of displacement: 19.510680835549195\n"
]
}
],
"source": [
"import statistics\n",
"print(\"Standard deviation of displacement:\", statistics.stdev(displacement_list))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -161,7 +252,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.1"
}
},
"nbformat": 4,
Expand Down
Loading