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
95 changes: 76 additions & 19 deletions bus/bus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,60 +32,117 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# variables\n",
"\n"
"got_in = (2,5,4,6)\n",
"got_out = (1,3,3,6)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(2, 1), (5, 3), (4, 3), (6, 6)]\n",
"The number of stops is 4\n"
]
}
],
"source": [
"# 1. Calculate the number of stops.\n",
"\n"
"\n",
"stops=[]\n",
"\n",
"for i in range(len(got_in)):\n",
" stops.append((got_in[i],got_out[i]))\n",
"\n",
"print(stops)\n",
"print(\"The number of stops is\", len(stops))\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 1, 0]\n"
]
}
],
"source": [
"# 2. Assign a variable a list whose elements are the number of passengers in each stop: \n",
"# 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.\n",
"\n"
"\n",
"pasg_by_stop = []\n",
"\n",
"for i in range(len(got_in)):\n",
" pasg_by_stop.append(stops[i][0]-stops[i][1])\n",
" \n",
"print(pasg_by_stop)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n"
]
}
],
"source": [
"# 3. Find the maximum occupation of the bus.\n",
"\n"
"max_pasg = max(pasg_by_stop)\n",
"\n",
"print(max_pasg)\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 19,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Standard Deviation of the occupation of bus is 0.816496580927726\n",
"The average occupation of the bus is 1.0\n"
]
}
],
"source": [
"# 4. Calculate the average occupation. And the standard deviation.\n",
"\n"
"\n",
"pasg_mean = sum(pasg_by_stop)/len(pasg_by_stop)\n",
"\n",
"import statistics \n",
"from statistics import stdev \n",
"\n",
"pasg_stdev = stdev(pasg_by_stop)\n",
"\n",
"print(\"Standard Deviation of the occupation of bus is\", pasg_stdev )\n",
"print(\"The average occupation of the bus is\", pasg_mean)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
}
],
Expand All @@ -105,7 +162,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
69 changes: 69 additions & 0 deletions bus/bus_exercise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#%% Change working directory from the workspace root to the ipynb file location. Turn this addition off with the DataScience.changeDirOnImportExport setting
# ms-python.python added
import os

try:
os.chdir(os.path.join(os.getcwd(), "bus/.ipynb_checkpoints"))
print(os.getcwd())
except:
pass
#%% [markdown]
# # Bus
#
# This bus has a passenger entry and exit control system to monitor the number of occupants it carries and thus detect when there is too high a capacity.
#
# At each stop the entry and exit of passengers is represented by a tuple consisting of two integer numbers.
# ```
# bus_stop = (in, out)
# ```
# The succession of stops is represented by a list of these tuples.
# ```
# stops = [(in1, out1), (in2, out2), (in3, out3), (in4, out4)]
# ```
#
# ## Goals:
# * lists, tuples
# * while/for loops
# * minimum, maximum, length
# * average, standard deviation
#
# ## Tasks
# 1. Calculate the number of stops.
# 2. Assign to a variable a list whose elements are the number of passengers at each stop (in-out),
# 3. Find the maximum occupation of the bus.
# 4. Calculate the average occupation. And the standard deviation.
#

#%%
# variables
##def bus_stop (in,out)

# Each item depends on the previous item in the list + in - out.
pass_in = [2, 3, 5, 7]
pass_out = (1, 5, 7, 8)
max_pass = max(len(pass_in), len(pass_out))
print(max_pass)
print("hello")

#%%
# 1. Calculate the number of stops.
stops = []
i = 0
print(stops)

while i < max_pass:
stops.append((pass_in[i], pass_out[i]))

print(stops)
print("hello")
#%%
# 2. Assign a variable a list whose elements are the number of passengers in each stop:


#%%
# 3. Find the maximum occupation of the bus.


#%%
# 4. Calculate the average occupation. And the standard deviation.

Loading