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
77 changes: 64 additions & 13 deletions bus/bus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,106 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# variables\n",
"\n"
"stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8 ), (4, 6), (2, 3)]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 1. Calculate the number of stops.\n",
"len(stops)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"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"
"stocking = []\n",
"passengers = 0\n",
"for stop in stops:\n",
" passengers = passengers + stop[0] - stop[1]\n",
" stocking.append(passengers)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 3. Find the maximum occupation of the bus.\n",
"\n"
"max(stocking)\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9.333333333333334\n",
"3.197221015541813\n"
]
}
],
"source": [
"# 4. Calculate the average occupation. And the standard deviation.\n",
"\n"
"average_occupation = sum(stocking)/len(stocking)\n",
"print (average_occupation)\n",
"\n",
"squared_deviations=[]\n",
"for i in stocking:\n",
" squared_deviation=(i - average_occupation)**2\n",
" squared_deviations.append(squared_deviation)\n",
"standard_deviation = (sum(squared_deviations)/len(squared_deviations))**0.5\n",
"print(standard_deviation)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -105,7 +156,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
141 changes: 124 additions & 17 deletions duel/duel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Assign 0 to each variable that stores the victories\n"
"# Assign 0 to each variable that stores the victories\n",
"gandalf_victories=0\n",
"saruman_victories=0"
]
},
{
Expand All @@ -58,18 +60,41 @@
"metadata": {},
"outputs": [],
"source": [
"# Execution of spell clashes\n"
"# Execution of spell clashes\n",
"spell_clashes=[]\n",
"for i in range(0,len(gandalf)):\n",
" clash_result = gandalf[i] - saruman[i]\n",
" spell_clashes.append(clash_result)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gandalf wins\n"
]
}
],
"source": [
"# We check who has won, do not forget the possibility of a draw.\n",
"# Print the result based on the winner.\n",
"\n"
"for i in spell_clashes:\n",
" if i < 0:\n",
" saruman_victories += 1\n",
" elif i > 0:\n",
" gandalf_victories += 1\n",
"\n",
"if saruman_victories > gandalf_victories:\n",
" print(\"Saruman wins\")\n",
"elif saruman_victories < gandalf_victories:\n",
" print(\"Gandalf wins\")\n",
"else:\n",
" print(\"Tie\")\n"
]
},
{
Expand Down Expand Up @@ -116,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -139,53 +164,135 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Assign spell power lists to variables\n",
"\n"
"gandalf_power = []\n",
"saruman_power = []\n",
"\n",
"for i in gandalf:\n",
" power = POWER[i]\n",
" gandalf_power.append(power)\n",
" \n",
"for i in saruman:\n",
" power = POWER[i]\n",
" saruman_power.append(power)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gandalf Wins\n"
]
}
],
"source": [
"# 2. A sorcerer wins if he succeeds in winning 3 spell clashes in a row.\n",
"\n",
"\n",
"# Execution of spell clashes\n",
"\n",
"spell_clashes=[]\n",
"for i in range(0,len(gandalf_power)):\n",
" clash_result = gandalf_power[i] - saruman_power[i]\n",
" spell_clashes.append(clash_result)\n",
"\n",
"\n",
"# check for 3 wins in a row\n",
"gandalf_pontuation = 0\n",
"saruman_pontuation = 0 \n",
"for i in spell_clashes:\n",
" if i < 0:\n",
" gandalf_pontuation = 0\n",
" saruman_pontuation = saruman_pontuation + 1\n",
" if saruman_pontuation == 3:\n",
" print(\"Saruman Wins\")\n",
" elif i > 0:\n",
" gandalf_pontuation = gandalf_pontuation + 1\n",
" saruman_pontuation = 0\n",
" if gandalf_pontuation == 3:\n",
" print(\"Gandalf Wins\")\n",
"\n",
"\n",
"\n",
"# check the winner\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"35.0\n",
"30.5\n"
]
}
],
"source": [
"# 3. Average of each of the spell lists.\n",
"\n"
"average_gandalf_power=sum(gandalf_power)/len(gandalf_power)\n",
"print(average_gandalf_power)\n",
"average_saruman_power=sum(saruman_power)/len(saruman_power)\n",
"print(average_saruman_power)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"16.881943016134134\n",
"15.56438241627338\n"
]
}
],
"source": [
"# 4. Standard deviation of each of the spell lists.\n",
"\n"
"\n",
"squared_deviations_gandalf=[]\n",
"for i in gandalf_power:\n",
" squared_deviation=(i - average_gandalf_power)**2\n",
" squared_deviations_gandalf.append(squared_deviation)\n",
"standard_deviation_gandalf = (sum(squared_deviations_gandalf)/len(squared_deviations_gandalf))**0.5\n",
"print(standard_deviation_gandalf)\n",
"\n",
"squared_deviations_saruman=[]\n",
"for i in saruman_power:\n",
" squared_deviation=(i - average_saruman_power)**2\n",
" squared_deviations_saruman.append(squared_deviation)\n",
"standard_deviation_saruman = (sum(squared_deviations_saruman)/len(squared_deviations_saruman))**0.5\n",
"print(standard_deviation_saruman)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -210,7 +317,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
Loading