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
160 changes: 142 additions & 18 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,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"source": [
"while True:\n",
" days += 1\n",
" snail_position += daily_distance\n",
" if snail_position >= well_height:\n",
" break\n",
" snail_position -= nightly_distance"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +86,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11\n"
]
}
],
"source": [
"print(days)"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +120,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"source": [
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +141,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"77\n",
"12\n"
]
}
],
"source": [
"print(max(advance_cm))\n",
"print(min(advance_cm))"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +167,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"17.90909090909091\n"
]
}
],
"source": [
"advance_cm_daily=[10,1,13,57,22,25,3,25,-8,14,35]\n",
"AVG=(sum(advance_cm_daily))/(len(advance_cm_daily))\n",
"print(AVG)"
]
},
{
"cell_type": "markdown",
Expand All @@ -137,6 +191,76 @@
"#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"38.09090909090909\n"
]
}
],
"source": [
"AVG=(sum(advance_cm))/(len(advance_cm))\n",
"print (AVG)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"VAR=sum((xi - AVG) ** 2 for xi in advance_cm) / len(advance_cm)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"294.44628099173553\n"
]
}
],
"source": [
"print(VAR)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"DEV=VAR**0.5"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"17.159437082600803\n"
]
}
],
"source": [
"print(DEV)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -161,7 +285,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
Loading