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

adding robot.md to the repository #22

Open
wants to merge 3 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
163 changes: 141 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 #snail starts at the bottom on day 0"
]
},
{
"cell_type": "markdown",
Expand All @@ -58,10 +65,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"source": [
"while snail_position<well_height:\n",
" days+=1 # another day passes...\n",
" snail_position+=daily_distance #distance walked during the day\n",
" if snail_position<well_height: #if after walking daily distance it´s still in the well...\n",
" snail_position-=nightly_distance #subtract nightly drop\n",
" else: #means that it reached the top during that day\n",
" break"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +87,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The snail takes 11 days to escape the well\n"
]
}
],
"source": [
"print('The snail takes {} days to escape the well'.format(days))"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +121,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The snail takes 5 days to escape the well\n"
]
}
],
"source": [
"days=0 #snail starts at the bottom on day 0\n",
"snail_position=0\n",
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"i=0\n",
"\n",
"while snail_position<well_height:\n",
" days+=1 # another day passes...\n",
" snail_position+=advance_cm[i]#distance walked during the day\n",
" i+=1 #increment distance list\n",
" if snail_position<well_height: #if after walking daily distance it´s still in the well...\n",
" snail_position-=nightly_distance #subtract nightly drop\n",
" else: #means that it reached the top during that day\n",
" break\n",
" \n",
"print('The snail takes {} days to escape the well'.format(days))"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +160,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The maximum displacement is 57 cm and the minimum displacement is 1 cm.\n"
]
}
],
"source": [
"days=0 #snail starts at the bottom on day 0\n",
"snail_position=0\n",
"advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n",
"i=0\n",
"displacement=[]\n",
"\n",
"while snail_position<well_height:\n",
" days+=1 # another day passes...\n",
" snail_position+=advance_cm[i]#distance walked during the day\n",
" if snail_position<well_height: #if after walking daily distance it´s still in the well...\n",
" snail_position-=nightly_distance #subtract nightly drop\n",
" else: #means that it reached the top during that day\n",
" displacement.append(advance_cm[i]) # in this situation there is no nightly distance to subtract since the snail escaped\n",
" break\n",
" displacement.append(advance_cm[i]-nightly_distance)\n",
" i+=1 #increment distance list\n",
" \n",
"print('The maximum displacement is {} cm and the minimum displacement is {} cm.'.format(max(displacement),min(displacement)))"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +201,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The average progress is 25.0 cm\n"
]
}
],
"source": [
"print ('The average progress is {} cm'.format(sum(displacement)/len(displacement))) "
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +225,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The standard deviation (manually calculated) of displacement is 21.587033144922902 cm\n",
"The standard deviation (calculated from statistics library) of displacement is 24.13503677229434 cm\n"
]
},
{
"data": {
"text/plain": [
"'the difference is due to the fact that the manual calculation assumes the given values constitute the total population\\nwhereas the statistics library uses the formula assuming an infinite population.'"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import statistics\n",
"\n",
"displacement_avg=sum(displacement)/len(displacement)\n",
"displacement_sq_avg=sum([i**2 for i in displacement])/len([i**2 for i in displacement])\n",
"\n",
"stdev_displacement=(displacement_sq_avg-displacement_avg**2)**0.5 # calculation according to stdev formula\n",
"\n",
"print('The standard deviation (manually calculated) of displacement is {} cm'.format(stdev_displacement))\n",
"\n",
"print ('The standard deviation (calculated from statistics library) of displacement is {} cm'.format(statistics.stdev(displacement)))\n",
"\n",
"#the difference is due to the fact that the manual calculation assumes the given values constitute\n",
"#the total population whereas the statistics library uses the formula assuming an infinite population\n"
]
}
],
"metadata": {
Expand All @@ -161,7 +280,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
Loading