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

Large diffs are not rendered by default.

325 changes: 302 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,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10\n"
]
}
],
"source": [
"well_height = 125\n",
"daily_distance = 30\n",
"nightly_distance = -20\n",
"snail_position = 0"
]
},
{
"cell_type": "markdown",
Expand All @@ -47,7 +60,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"days = 0 "
]
},
{
"cell_type": "markdown",
Expand All @@ -58,10 +73,71 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 130,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"start of day1\n",
"snail achieved 30 cm of height during day 1 morning\n",
"snail slided down to 10 cm of height during day 1 night\n",
"start of day2\n",
"snail achieved 40 cm of height during day 2 morning\n",
"snail slided down to 20 cm of height during day 2 night\n",
"start of day3\n",
"snail achieved 50 cm of height during day 3 morning\n",
"snail slided down to 30 cm of height during day 3 night\n",
"start of day4\n",
"snail achieved 60 cm of height during day 4 morning\n",
"snail slided down to 40 cm of height during day 4 night\n",
"start of day5\n",
"snail achieved 70 cm of height during day 5 morning\n",
"snail slided down to 50 cm of height during day 5 night\n",
"start of day6\n",
"snail achieved 80 cm of height during day 6 morning\n",
"snail slided down to 60 cm of height during day 6 night\n",
"start of day7\n",
"snail achieved 90 cm of height during day 7 morning\n",
"snail slided down to 70 cm of height during day 7 night\n",
"start of day8\n",
"snail achieved 100 cm of height during day 8 morning\n",
"snail slided down to 80 cm of height during day 8 night\n",
"start of day9\n",
"snail achieved 110 cm of height during day 9 morning\n",
"snail slided down to 90 cm of height during day 9 night\n",
"start of day10\n",
"snail achieved 120 cm of height during day 10 morning\n",
"snail slided down to 100 cm of height during day 10 night\n",
"start of day11\n",
"snail achieved 126 cm of height during day 11 morning and left the well\n",
"The snail took 11 days to escape the well\n"
]
}
],
"source": [
"well_height = 125\n",
"daily_distance = 30\n",
"nightly_distance = 20\n",
"snail_position = 0\n",
"days = 0\n",
"\n",
"days += 1\n",
"print(f\"start of day{days}\")\n",
"while snail_position <= well_height:\n",
" snail_position += daily_distance\n",
" if snail_position > well_height:\n",
" snail_position = snail_position - (snail_position - (well_height + 1))\n",
" elif snail_position <= well_height: \n",
" print(\"snail achieved\", snail_position,\"cm of height during day\", days, \"morning\")\n",
" snail_position = snail_position - nightly_distance\n",
" print(\"snail slided down to\", snail_position,\"cm of height during day\", days, \"night\")\n",
" days += 1\n",
" print(f\"start of day{days}\")\n",
"\n",
"print(f\"snail achieved {snail_position} cm of height during day {days} morning and left the well\\nThe snail took {days} days to escape the well\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +148,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 136,
"metadata": {},
"outputs": [],
"source": []
"source": [
"The snail took 10 days to escape the well"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +174,63 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 131,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"start of day1\n",
"snail has climbed 30 cm and achieved 30 cm of height during day 1 morning\n",
"snail slided down to 10 cm of height during day 1 night\n",
"start of day2\n",
"snail has climbed 21 cm and achieved 31 cm of height during day 2 morning\n",
"snail slided down to 11 cm of height during day 2 night\n",
"start of day3\n",
"snail has climbed 33 cm and achieved 44 cm of height during day 3 morning\n",
"snail slided down to 24 cm of height during day 3 night\n",
"start of day4\n",
"snail has climbed 77 cm and achieved 101 cm of height during day 4 morning\n",
"snail slided down to 81 cm of height during day 4 night\n",
"start of day5\n",
"snail has climbed 44 cm and achieved 125 cm of height during day 5 morning\n",
"snail slided down to 105 cm of height during day 5 night\n",
"start of day6\n",
"Snail could have climbed 45cm but he had to climb only 21 cm to reach 126 cm height and exit the well\n",
"The snail took 6 days to escape the well\n"
]
}
],
"source": [
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"well_height = 125\n",
"nightly_distance = 20\n",
"snail_position = 0\n",
"days = 0\n",
"\n",
"days += 1\n",
"print(f\"start of day{days}\")\n",
"while snail_position <= well_height:\n",
" \n",
" for dist in advance_cm:\n",
" snail_position += dist\n",
" \n",
" if snail_position > well_height:\n",
" pos = (dist - (snail_position - (well_height + 1)))\n",
" final_height = snail_position - dist + pos\n",
" print(f\"Snail could have climbed {dist}cm but he had to climb only {pos} cm to reach {final_height} cm height and exit the well\" )\n",
" break\n",
" \n",
" elif snail_position <= well_height: \n",
" print(\"snail has climbed\", dist,\"cm and achieved\", snail_position,\"cm of height during day\", days, \"morning\")\n",
" snail_position = snail_position - nightly_distance\n",
" print(\"snail slided down to\", snail_position,\"cm of height during day\", days, \"night\")\n",
" days += 1\n",
" print(f\"start of day{days}\")\n",
"\n",
"print(f\"The snail took {days} days to escape the well\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +242,54 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 133,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Minimun displacement in one day has been 1cm\n",
"Max displacement in one day has been 57cm\n"
]
}
],
"source": [
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"well_height = 125\n",
"nightly_distance = 20\n",
"snail_position = 0\n",
"days = 0\n",
"mm_displacement_list = []\n",
"\n",
"days += 1\n",
"#print(f\"start of day {days}\")\n",
"while snail_position <= well_height:\n",
" \n",
" for dist in advance_cm:\n",
" snail_position += dist\n",
" displacement = dist - nightly_distance\n",
" \n",
" if snail_position > well_height:\n",
" pos = (dist - (snail_position - (well_height + 1)))\n",
" final_height = snail_position - dist + pos\n",
" #print(f\"Snail could have climbed {dist}cm but he had to climb only {pos} cm to reach {final_height} cm height and exit the well\" )\n",
" mm_displacement_list.append(pos)\n",
" break\n",
" \n",
" elif snail_position <= well_height: \n",
" #print(\"snail has climbed\", dist,\"cm and achieved\", snail_position,\"cm of height during day\", days, \"morning\")\n",
" snail_position = snail_position - nightly_distance\n",
" #print(\"snail slided down to\", snail_position,\"cm of height during day\", days, \"night\")\n",
" days += 1\n",
" mm_displacement_list.append(displacement)\n",
" #print(f\"start of day {days}\")\n",
"\n",
"\n",
"\n",
"print(f\"Minimun displacement in one day has been {min(mm_displacement_list)}cm\")\n",
"print(f\"Max displacement in one day has been {max(mm_displacement_list)}cm\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +300,52 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 134,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The snail average progress is 21.0 cm per day\n"
]
}
],
"source": [
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"well_height = 125\n",
"nightly_distance = 20\n",
"snail_position = 0\n",
"days = 0\n",
"mm_displacement_list = []\n",
"\n",
"days += 1\n",
"#print(f\"start of day {days}\")\n",
"while snail_position <= well_height:\n",
" \n",
" for dist in advance_cm:\n",
" snail_position += dist\n",
" displacement = dist - nightly_distance\n",
" \n",
" if snail_position > well_height:\n",
" pos = (dist - (snail_position - (well_height + 1)))\n",
" final_height = snail_position - dist + pos\n",
" #print(f\"Snail could have climbed {dist}cm but he had to climb only {pos} cm to reach {final_height} cm height and exit the well\" )\n",
" mm_displacement_list.append(pos)\n",
" break\n",
" \n",
" elif snail_position <= well_height: \n",
" #print(\"snail has climbed\", dist,\"cm and achieved\", snail_position,\"cm of height during day\", days, \"morning\")\n",
" snail_position = snail_position - nightly_distance\n",
" #print(\"snail slided down to\", snail_position,\"cm of height during day\", days, \"night\")\n",
" days += 1\n",
" mm_displacement_list.append(displacement)\n",
" #print(f\"start of day {days}\")\n",
"\n",
"\n",
"avg = (sum(mm_displacement_list))/len(mm_displacement_list)\n",
"print(f\"The snail average progress is {avg} cm per day\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,15 +356,77 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 135,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Variance is: 315.0\n",
"Standard deviation is: 17.74823934929885\n"
]
}
],
"source": [
"\"\"\"\n",
"In statistics, the variance is a measure of how far individual (numeric) values in a dataset \n",
"are from the mean or average value.\n",
"\n",
"The standard deviation measures the amount of VARIATION or dispersion of a set of numeric values. \n",
"Standard deviation is the square root of variance σ2 and is denoted as σ. \"\"\"\n",
"\n",
"sqr_dev_mean = []\n",
"\n",
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"well_height = 125\n",
"nightly_distance = 20\n",
"snail_position = 0\n",
"days = 0\n",
"mm_displacement_list = []\n",
"\n",
"\n",
"days += 1\n",
"#print(f\"start of day {days}\")\n",
"while snail_position <= well_height:\n",
" \n",
" for dist in advance_cm:\n",
" snail_position += dist\n",
" displacement = dist - nightly_distance\n",
" \n",
" if snail_position > well_height:\n",
" pos = (dist - (snail_position - (well_height + 1)))\n",
" final_height = snail_position - dist + pos\n",
" #print(f\"Snail could have climbed {dist}cm but he had to climb only {pos} cm to reach {final_height} cm height and exit the well\" )\n",
" mm_displacement_list.append(pos)\n",
" break\n",
" \n",
" elif snail_position <= well_height: \n",
" #print(\"snail has climbed\", dist,\"cm and achieved\", snail_position,\"cm of height during day\", days, \"morning\")\n",
" snail_position = snail_position - nightly_distance\n",
" #print(\"snail slided down to\", snail_position,\"cm of height during day\", days, \"night\")\n",
" days += 1\n",
" mm_displacement_list.append(displacement)\n",
" #print(f\"start of day {days}\")\n",
"\n",
"\n",
"avg = (sum(mm_displacement_list))/len(mm_displacement_list)\n",
"#print(f\"The snail average progress is {avg}cm per day\")\n",
"\n",
"for x in mm_displacement_list:\n",
" y = (x - avg)**2\n",
" sqr_dev_mean.append(y)\n",
" i = sum(sqr_dev_mean)\n",
" n = len(sqr_dev_mean)\n",
" variance = i / n\n",
" std_dev = variance**(.5)\n",
"print(f\"Variance is: {variance}\\nStandard deviation is: {std_dev}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -161,7 +440,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
Loading