Skip to content
464 changes: 297 additions & 167 deletions 1.-Python/1.-Snail-and-Well/snail-and-well.ipynb

Large diffs are not rendered by default.

624 changes: 397 additions & 227 deletions 1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb

Large diffs are not rendered by default.

326 changes: 203 additions & 123 deletions 1.-Python/3.-Bus/bus.ipynb
Original file line number Diff line number Diff line change
@@ -1,125 +1,205 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://bit.ly/2VnXWr2\" width=\"100\" align=\"left\">"
]
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
},
"colab": {
"name": "bus.ipynb",
"provenance": []
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bus\n",
"\n",
"This bus has a passenger entry and exit control system to monitor the number of occupants it carries and thus detect when there are too many.\n",
"\n",
"At each stop, the entry and exit of passengers is represented by a tuple consisting of two integer numbers.\n",
"```\n",
"bus_stop = (in, out)\n",
"```\n",
"The succession of stops is represented by a list of these tuples.\n",
"```\n",
"stops = [(in1, out1), (in2, out2), (in3, out3), (in4, out4)]\n",
"```\n",
"\n",
"## Tools\n",
"You don't necessarily need to use all the tools. Maybe you opt to use some of them or completely different ones, they are given to help you shape the exercise. Programming exercises can be solved in many different ways.\n",
"* Data structures: **lists, tuples**\n",
"* Loop: **while/for loops**\n",
"* Functions: **min, max, len**\n",
"\n",
"## Tasks"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Variables\n",
"stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1. Calculate the number of stops."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2. Assign to a variable a list whose elements are the number of passengers at each stop (in-out).\n",
"Each item depends on the previous item in the list + in - out."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3. Find the maximum occupation of the bus."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4. Calculate the average occupation. And the standard deviation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "z_YHfQiB1XGF"
},
"source": [
"<img src=\"https://bit.ly/2VnXWr2\" width=\"100\" align=\"left\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Q_SSvLI31XGI"
},
"source": [
"# Bus\n",
"\n",
"This bus has a passenger entry and exit control system to monitor the number of occupants it carries and thus detect when there are too many.\n",
"\n",
"At each stop, the entry and exit of passengers is represented by a tuple consisting of two integer numbers.\n",
"```\n",
"bus_stop = (in, out)\n",
"```\n",
"The succession of stops is represented by a list of these tuples.\n",
"```\n",
"stops = [(in1, out1), (in2, out2), (in3, out3), (in4, out4)]\n",
"```\n",
"\n",
"## Tools\n",
"You don't necessarily need to use all the tools. Maybe you opt to use some of them or completely different ones, they are given to help you shape the exercise. Programming exercises can be solved in many different ways.\n",
"* Data structures: **lists, tuples**\n",
"* Loop: **while/for loops**\n",
"* Functions: **min, max, len**\n",
"\n",
"## Tasks"
]
},
{
"cell_type": "code",
"metadata": {
"id": "lgNOzt3C1XGI"
},
"source": [
"# Variables\n",
"stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n",
"movement = []\n",
"occupation = []"
],
"execution_count": 1,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "rLzsRyFa1XGJ"
},
"source": [
"#### 1. Calculate the number of stops."
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "C1qp08Vs1XGJ",
"outputId": "212ffadb-e1bc-4eb7-f0df-33163db2f20b"
},
"source": [
"total_stops = len(stops)\n",
"print(\"The total number of bus stops is\", total_stops)"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"The total number of bus stops is 9\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Kpvvz1w01XGK"
},
"source": [
"#### 2. Assign to a variable a list whose elements are the number of passengers at each stop (in-out).\n",
"Each item depends on the previous item in the list + in - out."
]
},
{
"cell_type": "code",
"metadata": {
"id": "X5VMevZr1XGK"
},
"source": [
"for up,down in stops:\n",
" movement.append(up - down)\n",
"\n",
"for i in range(total_stops):\n",
" occupation.append(sum(movement[0:i+1]))"
],
"execution_count": 3,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "DQZrYZPd1XGK"
},
"source": [
"#### 3. Find the maximum occupation of the bus."
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ueI7jmx01XGL",
"outputId": "0ef02edd-9e47-4de0-a290-a7ace05c6e59"
},
"source": [
"print(\"The maximum occupation in the bus is\", max(occupation))"
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": [
"The maximum occupation in the bus is 14\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Q2PgsIxM1XGL"
},
"source": [
"#### 4. Calculate the average occupation. And the standard deviation."
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "0aVwHdMS1XGL",
"outputId": "0cc1ac31-d112-4218-bc94-29d7a2e88b32"
},
"source": [
"print(\"The average occupation is\", round((sum(occupation)/total_stops), 2))\n",
"import statistics\n",
"print(\"The standard deviation of the occupation is\", round(statistics.stdev(occupation), 2))"
],
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": [
"The average occupation is 9.33\n",
"The standard deviation of the occupation is 3.39\n"
],
"name": "stdout"
}
]
}
]
}
Loading