Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-work Minerva Liste #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
167 changes: 148 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": 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,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"source": [
"while (snail_position <= well_height):\n",
" snail_position += daily_distance\n",
" if (snail_position > well_height):\n",
" days += 1\n",
" else:\n",
" days += 1\n",
" snail_position += nightly_distance\n",
" "
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +88,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"It will take the snake 11 days to scape the well.\n"
]
}
],
"source": [
"print(\"\")\n",
"print(\"It will take the snake\", days, \"days to scape the well.\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +124,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"It will take the snake 6 days to scape the well.\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",
"days = 0\n",
"\n",
"for i in advance_cm:\n",
" if (snail_position <= well_height):\n",
" snail_position += i\n",
" if (snail_position > well_height):\n",
" days += 1\n",
" else:\n",
" days += 1\n",
" snail_position += nightly_distance\n",
"\n",
"print(\"\")\n",
"print(\"It will take the snake\", days, \"days to scape the well.\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +166,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"The maximum displacement in one day is 57 cm.\n",
"The minimum displacement in one day is 1 cm.\n"
]
}
],
"source": [
"real_daily_distance = advance_cm[:days]\n",
"displacement = []\n",
"\n",
"for i in real_daily_distance[:(days-1)]:\n",
" x = i + nightly_distance\n",
" displacement.append(x)\n",
"\n",
"for i in real_daily_distance[(days-1):]:\n",
" displacement.append(i)\n",
"\n",
"print(\"\")\n",
"print(\"The maximum displacement in one day is\", (max(displacement)), \"cm.\")\n",
"print(\"The minimum displacement in one day is\", (min(displacement)), \"cm.\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +204,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"The average progress of the snake is 25.0 .\n"
]
}
],
"source": [
"average_progress = sum(displacement)/len(displacement)\n",
"\n",
"print(\"\")\n",
"print(\"The average progress of the snake is\", average_progress, \".\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -137,6 +230,42 @@
"#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"The standard deviation for the snake displacement is 19.87460691435179 .\n"
]
}
],
"source": [
"squared_deviation_around_mean = []\n",
"\n",
"for i in displacement:\n",
" x = (i - average_progress)**2\n",
" squared_deviation_around_mean.append(x)\n",
"\n",
"variance = sum(squared_deviation_around_mean)/len(squared_deviation_around_mean)\n",
"\n",
"standard_deviation = variance**0.5\n",
"\n",
"print(\"\")\n",
"print(\"The standard deviation for the snake displacement is\", standard_deviation, \".\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -161,7 +290,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
Loading