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
183 changes: 160 additions & 23 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": 4,
"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": 5,
"metadata": {},
"outputs": [],
"source": []
"source": [
"days=0"
]
},
{
"cell_type": "markdown",
Expand All @@ -58,10 +65,58 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Day 1 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 2 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 3 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 4 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 5 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 6 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 7 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 8 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 9 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 10 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 11 :\n",
"The snail has climbed 30 cm.\n"
]
}
],
"source": [
"while snail_position<well_height:\n",
" print(\"Day\",days+1,\":\")\n",
" snail_position=snail_position+daily_distance\n",
" print(\"The snail has climbed\",daily_distance,\"cm.\")\n",
" if snail_position<well_height:\n",
" snail_position=snail_position-nightly_distance\n",
" print(\"The snail has fallen\",nightly_distance,\"cm.\")\n",
" days=days+1"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +127,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The snail has climbed the well! It only took it 11 days\n"
]
}
],
"source": [
"print(\"The snail has climbed the well! It only took it\",days,\"days\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +161,49 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Day 1 :\n",
"The snail has climbed 30 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 2 :\n",
"The snail has climbed 21 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 3 :\n",
"The snail has climbed 33 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 4 :\n",
"The snail has climbed 77 cm.\n",
"The snail has fallen 20 cm.\n",
"Day 5 :\n",
"The snail has climbed 44 cm.\n",
"The snail has climbed the well! It only took it 5 days\n"
]
}
],
"source": [
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"nightly_distance=20\n",
"snail_position=0\n",
"days=0\n",
"displacement=[]\n",
"while snail_position<well_height:\n",
" print(\"Day\",days+1,\":\")\n",
" snail_position=snail_position+advance_cm[days]\n",
" print(\"The snail has climbed\",advance_cm[days],\"cm.\")\n",
" if snail_position<well_height:\n",
" snail_position=snail_position-nightly_distance\n",
" print(\"The snail has fallen\",nightly_distance,\"cm.\")\n",
" displacement.append(advance_cm[days]-nightly_distance)\n",
" days=days+1\n",
"displacement.append(advance_cm[days])\n",
"print(\"The snail has climbed the well! It only took it\",days,\"days\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +215,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The maximum displacement in one day was 57 cm\n",
"The minimum displacement in one day was 1 cm\n"
]
}
],
"source": [
"print(\"The maximum displacement in one day was\",max(displacement),\"cm\")\n",
"print(\"The minimum displacement in one day was\",min(displacement),\"cm\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +241,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The average progress was 25.2 cm\n"
]
}
],
"source": [
"print(\"The average progress was\",sum(displacement)/len(displacement),\"cm\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +265,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The standard deviation of its displacement was 24.335159748807897 cm\n"
]
}
],
"source": [
"import statistics\n",
"print(\"The standard deviation of its displacement was\",statistics.stdev(displacement),\"cm\")"
]
}
],
"metadata": {
Expand All @@ -161,7 +298,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down
Loading