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
Binary file added .DS_Store
Binary file not shown.
Binary file added 1.-Python/.DS_Store
Binary file not shown.
Binary file added 1.-Python/1.-Snail-and-Well/.DS_Store
Binary file not shown.
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,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the snail has escaped\n"
]
}
],
"source": [
"well_height = 125\n",
"daily_distance = 30\n",
"nightly_distance = -20\n",
"snail_position = 0 \n",
"days = 0\n",
"while snail_position < well_height:\n",
" snail_position += daily_distance \n",
" snail_position += nightly_distance\n",
" days += 1\n",
"\n",
"print(\"the snail has escaped\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +99,32 @@
},
{
"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 escape\n"
]
}
],
"source": [
"well_height = 125\n",
"daily_distance = 30\n",
"nightly_distance = -20\n",
"snail_position = 0 \n",
"days = 0\n",
"\n",
"while snail_position < well_height:\n",
" snail_position += daily_distance \n",
" snail_position += nightly_distance\n",
" days += 1\n",
"\n",
"\n",
"print(\"the snail needs\", days, \"days to escape\")\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +145,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the snail needs 11 days to escape\n"
]
}
],
"source": [
"well_height = 125\n",
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"snail_position = 0 \n",
"days = 0\n",
"\n",
"while snail_position < well_height:\n",
" for i in advance_cm:\n",
" snail_position += i\n",
" snail_position += nightly_distance\n",
" days += 1\n",
"\n",
"print(\"the snail needs\", days, \"days to escape\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +181,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the maximum displacement is 57\n",
"the minimum displacement is -8\n"
]
}
],
"source": [
"print(\"the maximum displacement is\", max(advance_cm) + nightly_distance)\n",
"print(\"the minimum displacement is\", min(advance_cm) + nightly_distance)"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +207,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the average displacement is 18.09090909090909\n"
]
}
],
"source": [
"avg = (sum(advance_cm) + nightly_distance * days)/len(advance_cm)\n",
"print(\"the average displacement is\", avg)"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +232,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the standard deviation is 26.35234868074828\n"
]
}
],
"source": [
"var = sum((i-avg)**2 for i in advance_cm) / len(advance_cm)\n",
"std = var**0.5\n",
"print(\"the standard deviation is\",std)"
]
}
],
"metadata": {
Expand All @@ -161,7 +266,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
Loading