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 #227

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
Binary file added 1.-Python/.DS_Store
Binary file not shown.
204 changes: 186 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 @@ -28,6 +28,20 @@
"#### 1. Assign the challenge data to variables with representative names: `well_height`, `daily_distance`, `nightly_distance` and `snail_position`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"well_height=125\n",
"daily_distance=30\n",
"nightly_distance=20\n",
"snail_position=0"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -47,7 +61,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"days=0"
]
},
{
"cell_type": "markdown",
Expand All @@ -58,10 +74,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\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=snail_position + daily_distance - nightly_distance\n",
" days = days + 1\n",
" \n",
"print(days)"
]
},
{
"cell_type": "markdown",
Expand All @@ -72,10 +108,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\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=snail_position + daily_distance - nightly_distance\n",
" days = days + 1\n",
" \n",
"print(days)"
]
},
{
"cell_type": "markdown",
Expand All @@ -96,10 +152,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"130\n",
"6\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",
"day=0\n",
"\n",
"for daily_distance in advance_cm:\n",
"\tif snail_position < well_height:\n",
" \t\tsnail_position = snail_position + daily_distance - nightly_distance\n",
" \t\tday=day+1\n",
"\telse:\n",
"\t\t\tprint(snail_position)\n",
"\t\t\tprint(day)\n",
"\t\t\tbreak"
]
},
{
"cell_type": "markdown",
Expand All @@ -111,10 +191,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"57\n",
"1\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",
"day=0\n",
"daily_displacement=[]\n",
"\n",
"for daily_distance in advance_cm:\n",
"\tif snail_position < well_height:\n",
" \t\tsnail_position = snail_position + daily_distance - nightly_distance\n",
" \t\tdaily_displacement.append(daily_distance-nightly_distance)\n",
" \t\tday=day+1\n",
"\telse:\n",
"\t\t\tprint(max(daily_displacement))\n",
"\t\t\tprint(min(daily_displacement))\n",
"\t\t\tbreak"
]
},
{
"cell_type": "markdown",
Expand All @@ -125,10 +231,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"21.666666666666668\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",
"day=0\n",
"daily_displacement=[]\n",
"\n",
"for daily_distance in advance_cm:\n",
"\tif snail_position < well_height:\n",
" \t\tsnail_position = snail_position + daily_distance - nightly_distance\n",
" \t\tdaily_displacement.append(daily_distance-nightly_distance)\n",
" \t\tday=day+1\n",
"\telse:\n",
"\t\t\tprint(sum(daily_displacement)/len(daily_displacement))\n",
"\t\t\tbreak\n",
" "
]
},
{
"cell_type": "markdown",
Expand All @@ -137,6 +268,43 @@
"#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"17.81073334319006\n",
"17.81073334319006\n",
"17.81073334319006\n",
"17.81073334319006\n",
"17.81073334319006\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",
"day=0\n",
"daily_displacement=[]\n",
"\n",
"for daily_distance in advance_cm:\n",
"\tif snail_position < well_height:\n",
" \t\tsnail_position = snail_position + daily_distance - nightly_distance\n",
" \t\tdaily_displacement.append(daily_distance-nightly_distance)\n",
" \t\tday=day+1\n",
"\telse:\n",
"\t\t\tdisplacement_mean = sum(daily_displacement)/len(daily_displacement)\n",
"\t\t\tvariance = sum([(x-displacement_mean)**2 for x in daily_displacement])/len(daily_displacement)\n",
"\t\t\tstandard_dev = variance**0.5\n",
"\t\t\tprint(standard_dev)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -147,7 +315,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -161,7 +329,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
Loading