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
115 changes: 99 additions & 16 deletions bus/bus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,136 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 47,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter num of onboarded riders, *Enter 'end' as finished: 40\n",
"Enter number of passengers offboarded:0\n",
"Enter num of onboarded riders, *Enter 'end' as finished: 12\n",
"Enter number of passengers offboarded:15\n",
"Enter num of onboarded riders, *Enter 'end' as finished: 9\n",
"Enter number of passengers offboarded:34\n",
"Enter num of onboarded riders, *Enter 'end' as finished: 34\n",
"Enter number of passengers offboarded:46\n",
"Enter num of onboarded riders, *Enter 'end' as finished: end\n",
"[(40, 0), (12, 15), (9, 34), (34, 46)]\n"
]
}
],
"source": [
"# variables\n",
"\n"
"stops=[]\n",
"in_pass=0\n",
"\n",
"while in_pass != 'end':\n",
" in_pass=input(\"Enter num of onboarded riders, *Enter 'end' as finished: \")\n",
" if in_pass != 'end':\n",
" in_pass=int(in_pass)\n",
" out_pass=int(input(\"Enter number of passengers offboarded:\"))\n",
" bus_stop = (in_pass,out_pass)\n",
" stops.append(bus_stop)\n",
" else:\n",
" break\n",
"\n",
"print(stops)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 48,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 1. Calculate the number of stops.\n",
"\n"
"# 1. Calculate the number of stops\n",
"len(stops)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 52,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of passengers in each stops: [40, 37, 12, 0]\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"
"occupation=[]\n",
"num_pass=0\n",
"\n",
"for i in range(0,(len(stops))):\n",
" num_pass += stops[i][0]- stops[i][1]\n",
" occupation.append(num_pass)\n",
"\n",
"print(\"Number of passengers in each stops:\", occupation)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 55,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Max occupation is 40 passengers.\n"
]
}
],
"source": [
"# 3. Find the maximum occupation of the bus.\n",
"\n",
"\n",
"print(\"Max occupation is\", max(occupation),\"passengers.\")\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 57,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average occupation: 22.25\n",
"Standard deviation: 16.82817577754642\n"
]
}
],
"source": [
"# 4. Calculate the average occupation. And the standard deviation.\n",
"\n"
"\n",
"\n",
"mean_o=(sum(occupation)/len(occupation))\n",
"stdv_o=(sum(((i-mean_o)**2) for i in occupation)/len(occupation))**0.5\n",
"\n",
"print(\"Average occupation: \",mean_o)\n",
"print(\"Standard deviation: \",stdv_o)"
]
},
{
Expand All @@ -105,7 +188,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
Empty file added crusine.md
Empty file.
Loading