Skip to content
Open
115 changes: 100 additions & 15 deletions bus/bus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,138 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# variables\n",
"\n"
"stops = [(5,0),(8,2),(5,3),(7,4)]\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 1. Calculate the number of stops.\n",
"\n"
"\n",
"len(stops)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[10, 4, 3, 3, 5, 1, 5, 4, 2]\n",
"[0, 1, 5, 4, 1, 5, 8, 6, 3]\n",
"[10, 13, 11, 10, 14, 10, 7, 5, 4]\n"
]
}
],
"source": [
"# 2. Assign a variable a list whose elements are the number of passengers in each stop: \n",
"# Each item depends on the previous item in the list + in - out.\n",
"\n"
"stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8 ), (4, 6), (2, 3)]\n",
"bus_in = []\n",
"for i in stops:\n",
" bus_in.append(i [0])\n",
"print(bus_in)\n",
"\n",
"bus_out = []\n",
"\n",
"for j in stops:\n",
" bus_out.append(j [1])\n",
"print(bus_out)\n",
"\n",
"bus_occupied=[]\n",
"total = 0\n",
"for x,y in zip(bus_in, bus_out):\n",
" total += x-y\n",
" bus_occupied.append(total)\n",
"print(bus_occupied)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 3. Find the maximum occupation of the bus.\n",
"\n"
"\n",
"max(bus_occupied)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"9.333333333333334"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 4. Calculate the average occupation. And the standard deviation.\n",
"\n"
"\n",
"sum(bus_occupied)/len(bus_occupied)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.391164991562634"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# standard deviation\n",
"import statistics\n",
"statistics.stdev(bus_occupied)"
]
},
{
Expand All @@ -105,7 +190,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
Loading