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
134 changes: 112 additions & 22 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": 1,
"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": 2,
"metadata": {},
"outputs": [],
"source": []
"source": [
"days = 0"
]
},
{
"cell_type": "markdown",
Expand All @@ -58,10 +65,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"source": [
"while (snail_position < well_height):\n",
" 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": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The snail needs 13 days to reach the top of the well.\n"
]
}
],
"source": [
"print (\"The snail needs \"+ str(days) +\" days to reach the top of the well.\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +117,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The snail needs 6 days to reach the top of the well.\n"
]
}
],
"source": [
"well_height = 125\n",
"daily_distance = [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 += daily_distance[days] + nightly_distance\n",
" days += 1\n",
" \n",
"print (\"The snail needs \"+ str(days) +\" days to reach the top of the well.\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +153,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The maximun displacement is: 77\n",
"The minimum displacement is: 12\n",
"The displacement to get out of the well was 250 cm\n"
]
}
],
"source": [
"print (\"The maximun displacement is: \"+ str(max(daily_distance)))\n",
"print (\"The minimum displacement is: \"+ str(min(daily_distance)))\n",
"\n",
"print(\"The displacement to get out of the well was \"+ str(sum(daily_distance[:days])) +\" cm\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +182,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The average progress is 21.666666666666668\n"
]
}
],
"source": [
"daily_progress = []\n",
"for distance in daily_distance[:days] : \n",
" daily_progress.append(distance + nightly_distance)\n",
"\n",
"mean = sum(daily_progress)/len(daily_progress)\n",
"\n",
"print (\"The average progress is \"+str(mean))"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +212,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The standard deviaton of its displacement is 17.81073334319006\n"
]
}
],
"source": [
"from math import sqrt\n",
"\n",
"denominator = 0\n",
"for progress in daily_progress: \n",
" denominator += pow(progress - mean, 2)\n",
"stdev = sqrt(denominator/len(daily_progress))\n",
"\n",
"print (\"The standard deviaton of its displacement is \"+ str(stdev))"
]
}
],
"metadata": {
Expand All @@ -161,7 +251,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.7"
}
},
"nbformat": 4,
Expand Down
Loading