diff --git a/1.-Python/1.-Snail-and-Well/.ipynb_checkpoints/snail-and-well-checkpoint.ipynb b/1.-Python/1.-Snail-and-Well/.ipynb_checkpoints/snail-and-well-checkpoint.ipynb new file mode 100644 index 000000000..f68b1fdc7 --- /dev/null +++ b/1.-Python/1.-Snail-and-Well/.ipynb_checkpoints/snail-and-well-checkpoint.ipynb @@ -0,0 +1,266 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# The Snail and the Well\n", + "\n", + "A snail falls at the bottom of a 125 cm well. Each day the snail rises 30 cm. But at night, while sleeping, slides 20 cm because the walls are wet. How many days does it take for the snail to escape the well?\n", + "\n", + "**Hint**: The snail gets out of the well when it surpasses the 125cm of height.\n", + "\n", + "## Tools\n", + "\n", + "1. Loop: **while**\n", + "2. Conditional statements: **if-else**\n", + "3. Function: **print()**\n", + "\n", + "## Tasks\n", + "\n", + "#### 1. Assign the challenge data to variables with representative names: `well_height`, `daily_distance`, `nightly_distance` and `snail_position`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "well_height = 125\n", + "daily_distance = 30\n", + "nightly_distance = 20\n", + "snail_position = 0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Create a variable `days` to keep count of the days that pass until the snail escapes the well. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "days = 0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the solution to the challenge using the variables defined above. " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "while snail_position < well_height:\n", + " if int(days) == days:\n", + " snail_position += daily_distance\n", + " days += 0.5\n", + " else:\n", + " snail_position -= nightly_distance\n", + " days += 0.5\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Print the solution." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.5 days take for the snail to escape the well.\n" + ] + } + ], + "source": [ + "print(days,\" days take for the snail to escape the well.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus\n", + "The distance traveled by the snail each day is now defined by a list.\n", + "```\n", + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "```\n", + "On the first day, the snail rises 30cm but during the night it slides 20cm. On the second day, the snail rises 21cm but during the night it slides 20cm, and so on. \n", + "\n", + "#### 1. How many days does it take for the snail to escape the well?\n", + "Follow the same guidelines as in the previous challenge.\n", + "\n", + "**Hint**: Remember that the snail gets out of the well when it surpasses the 125cm of height." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "well_height = 125\n", + "advance_cm =[30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "nightly_distance = 20\n", + "snail_position = 0\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. What is its maximum displacement in one day? And its minimum? Calculate the displacement using only the travel distance of the days used to get out of the well. \n", + "**Hint**: Remember that displacement means the total distance risen taking into account that the snail slides at night. " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.5 days take for the snail to secape the well.\n" + ] + } + ], + "source": [ + "days = 0\n", + "i = 0\n", + "\n", + "while snail_position < well_height:\n", + " if int(days) == days:\n", + " snail_position += advance_cm[i]\n", + " days += 0.5\n", + " i += 1\n", + " else:\n", + " snail_position -= nightly_distance\n", + " days += 0.5\n", + "\n", + "print(days, \" days take for the snail to secape the well.\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. What is its average progress? Take into account the snail slides at night." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max of displacement: 57 \n", + "Min of displacement: 1\n" + ] + } + ], + "source": [ + "advance_cm =[30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "nightly_distance = 20\n", + "\n", + "displacement = []\n", + "\n", + "for i in range(0,5):\n", + " dis = advance_cm[i] - nightly_distance\n", + " displacement.append(dis)\n", + "\n", + "print(\"Max of displacement: \", max(displacement), \"\\nMin of displacement: \" , min(displacement))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "standard deviation: 23.2379000772445\n" + ] + } + ], + "source": [ + "dif = 0\n", + "avg = sum(displacement)/len(displacement)\n", + "\n", + "for i in range (0,5):\n", + " dif += int((displacement[i]-avg)**2)\n", + " \n", + "standard_deviation = (dif/(4.5 - 1))**0.5\n", + "\n", + "print(\"standard deviation: \", 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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb b/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb index 34021448a..f68b1fdc7 100644 --- a/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb +++ b/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb @@ -30,10 +30,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "well_height = 125\n", + "daily_distance = 30\n", + "nightly_distance = 20\n", + "snail_position = 0" + ] }, { "cell_type": "markdown", @@ -44,10 +49,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "days = 0" + ] }, { "cell_type": "markdown", @@ -58,10 +65,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "while snail_position < well_height:\n", + " if int(days) == days:\n", + " snail_position += daily_distance\n", + " days += 0.5\n", + " else:\n", + " snail_position -= nightly_distance\n", + " days += 0.5\n" + ] }, { "cell_type": "markdown", @@ -72,10 +87,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.5 days take for the snail to escape the well.\n" + ] + } + ], + "source": [ + "print(days,\" days take for the snail to escape the well.\")" + ] }, { "cell_type": "markdown", @@ -96,10 +121,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "well_height = 125\n", + "advance_cm =[30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "nightly_distance = 20\n", + "snail_position = 0\n" + ] }, { "cell_type": "markdown", @@ -111,10 +141,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.5 days take for the snail to secape the well.\n" + ] + } + ], + "source": [ + "days = 0\n", + "i = 0\n", + "\n", + "while snail_position < well_height:\n", + " if int(days) == days:\n", + " snail_position += advance_cm[i]\n", + " days += 0.5\n", + " i += 1\n", + " else:\n", + " snail_position -= nightly_distance\n", + " days += 0.5\n", + "\n", + "print(days, \" days take for the snail to secape the well.\")\n" + ] }, { "cell_type": "markdown", @@ -125,10 +177,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max of displacement: 57 \n", + "Min of displacement: 1\n" + ] + } + ], + "source": [ + "advance_cm =[30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "nightly_distance = 20\n", + "\n", + "displacement = []\n", + "\n", + "for i in range(0,5):\n", + " dis = advance_cm[i] - nightly_distance\n", + " displacement.append(dis)\n", + "\n", + "print(\"Max of displacement: \", max(displacement), \"\\nMin of displacement: \" , min(displacement))\n" + ] }, { "cell_type": "markdown", @@ -137,6 +209,31 @@ "#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night." ] }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "standard deviation: 23.2379000772445\n" + ] + } + ], + "source": [ + "dif = 0\n", + "avg = sum(displacement)/len(displacement)\n", + "\n", + "for i in range (0,5):\n", + " dif += int((displacement[i]-avg)**2)\n", + " \n", + "standard_deviation = (dif/(4.5 - 1))**0.5\n", + "\n", + "print(\"standard deviation: \", standard_deviation)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -161,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/1.-Python/2.-Duel-of-Sorcerers/.ipynb_checkpoints/duel-of-sorcerers-checkpoint.ipynb b/1.-Python/2.-Duel-of-Sorcerers/.ipynb_checkpoints/duel-of-sorcerers-checkpoint.ipynb new file mode 100644 index 000000000..aa6ae238b --- /dev/null +++ b/1.-Python/2.-Duel-of-Sorcerers/.ipynb_checkpoints/duel-of-sorcerers-checkpoint.ipynb @@ -0,0 +1,377 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Duel of Sorcerers\n", + "You are witnessing an epic battle between two powerful sorcerers: Gandalf and Saruman. Each sorcerer has 10 spells of variable power in their mind and they are going to throw them one after the other. The winner of the duel will be the one who wins more of those clashes between spells. Spells are represented as a list of 10 integers whose value equals the power of the spell.\n", + "```\n", + "gandalf = [10, 11, 13, 30, 22, 11, 10, 33, 22, 22]\n", + "saruman = [23, 66, 12, 43, 12, 10, 44, 23, 12, 17]\n", + "```\n", + "For example:\n", + "- The first clash is won by Saruman: 10 against 23.\n", + "- The second clash is won by Saruman: 11 against 66.\n", + "- ...\n", + "\n", + "You will create two variables, one for each sorcerer, where the sum of clashes won will be stored. Depending on which variable is greater at the end of the duel, you will show one of the following three results on the screen:\n", + "* Gandalf wins\n", + "* Saruman wins\n", + "* Tie\n", + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 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", + "\n", + "1. Data structures: **lists, dictionaries**\n", + "2. Loop: **for loop**\n", + "3. Conditional statements: **if-elif-else**\n", + "4. Functions: **range(), len(), print()**\n", + "\n", + "## Tasks\n", + "\n", + "#### 1. Create two variables called `gandalf` and `saruman` and assign them the spell power lists. Create a variable called `spells` to store the number of spells that the sorcerers cast. " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "gandolf = [10, 11, 13, 30, 22, 11, 10, 33, 22, 22]\n", + "saruman = [23, 66, 12, 43, 12, 10, 44, 23, 12, 17]\n", + "spells =len(gandolf)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Create two variables called `gandalf_wins` and `saruman_wins`. Set both of them to 0. \n", + "You will use these variables to count the number of clashes each sorcerer wins. " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "gandolf_wins =0\n", + "saruman_wins =0\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Using the lists of spells of both sorcerers, update variables `gandalf_wins` and `saruman_wins` to count the number of times each sorcerer wins a clash. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(0,spells):\n", + " if gandolf[i] > saruman[i]:\n", + " gandolf_wins += 1\n", + " elif gandolf[i] < saruman[i]:\n", + " saruman_wins += 1\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Who won the battle?\n", + "Print `Gandalf wins`, `Saruman wins` or `Tie` depending on the result. " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--- Gandalf wins ---\n" + ] + } + ], + "source": [ + "if (gandolf_wins > saruman_wins): \n", + " print(\"--- Gandalf wins ---\")\n", + "elif (saruman_wins > gandolf_wins ): \n", + " print(\"--- Saruman wins ---\")\n", + "else:\n", + " print(\"--- Tie ---\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus\n", + "\n", + "In this bonus challenge, you'll need to check the winner of the battle but this time, a sorcerer wins if he succeeds in winning 3 spell clashes in a row.\n", + "\n", + "Also, the spells now have a name and there is a dictionary that associates that name to a power.\n", + "\n", + "```\n", + "POWER = {\n", + " 'Fireball': 50, \n", + " 'Lightning bolt': 40, \n", + " 'Magic arrow': 10, \n", + " 'Black Tentacles': 25, \n", + " 'Contagion': 45\n", + "}\n", + "\n", + "gandalf = ['Fireball', 'Lightning bolt', 'Lightning bolt', 'Magic arrow', 'Fireball', \n", + " 'Magic arrow', 'Lightning bolt', 'Fireball', 'Fireball', 'Fireball']\n", + "saruman = ['Contagion', 'Contagion', 'Black Tentacles', 'Fireball', 'Black Tentacles', \n", + " 'Lightning bolt', 'Magic arrow', 'Contagion', 'Magic arrow', 'Magic arrow']\n", + "```\n", + "\n", + "#### 1. Create variables `POWER`, `gandalf` and `saruman` as seen above. Create a variable called `spells` to store the number of spells that the sorcerers cast. " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "power = {'Fireball':50, 'Lightning bolt':40, 'Magic arrow': 10, 'Black Tentacles':25, 'Contagion':45}\n", + "\n", + "gandalf = ['Fireball', 'Lightning bolt', 'Lightning bolt', 'Magic arrow', 'Fireball', 'Magic arrow', \n", + " 'Lightning bolt', 'Fireball', 'Fireball', 'Fireball']\n", + "\n", + "saruman = ['Contagion', 'Contagion', 'Black Tentacles', 'Fireball', 'Black Tentacles','Lightning bolt',\n", + " 'Magic arrow', 'Contagion', 'Magic arrow', 'Magic arrow']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Create two variables called `gandalf_wins` and `saruman_wins`. Set both of them to 0. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_wins = 0\n", + "saruman_wins =0\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Create two variables called `gandalf_power` and `saruman_power` to store the list of spell powers of each sorcerer." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_power = []\n", + "saruman_power =[]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. The battle starts! Using the variables you've created above, code the execution of spell clashes. Remember that a sorcerer wins if he succeeds in winning 3 spell clashes in a row. \n", + "If a clash ends up in a tie, the counter of wins in a row is not restarted to 0. Remember to print who is the winner of the battle. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf is the winner\n", + "Gandalf is the winner\n" + ] + } + ], + "source": [ + "spells = list(power.keys())\n", + "spells_power = list(power.values())\n", + "\n", + "g_spell_power = []\n", + "s_spell_power = []\n", + "\n", + "l = len(gandalf)\n", + "p = len(power)\n", + "\n", + "for i in range(0, l):\n", + " for j in range(0,p):\n", + " if gandalf[i] == spells[j]:\n", + " g = spells_power[j]\n", + " g_spell_power.append(g) \n", + " \n", + "for i in range(0, l):\n", + " for j in range(0,p): \n", + " if saruman[i] == spells[j]:\n", + " s = spells_power[j]\n", + " s_spell_power.append(s)\n", + "\n", + "\n", + " \n", + "for i in range(0,l-2):\n", + " if (g_spell_power[i] > s_spell_power[i]) & (g_spell_power[i+1] > s_spell_power[i+1]) & (g_spell_power[i+2] > s_spell_power[i+2]):\n", + " print('Gandalf is the winner')\n", + " \n", + " elif (g_spell_power[i] < s_spell_power[i]) & (g_spell_power[i+1] < s_spell_power[i+1]) & (g_spell_power[i+2] < s_spell_power[i+2]):\n", + " print('Saruman is the winner')\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5. Find the average spell power of Gandalf and Saruman. " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf: 39.0 \n", + "Saruman : 30.5\n" + ] + } + ], + "source": [ + "g_avg_spell_power = sum(g_spell_power)/len(g_spell_power)\n", + "\n", + "s_avg_spell_power = sum(s_spell_power)/len(s_spell_power)\n", + " \n", + "print('Gandalf: ', g_avg_spell_power,'\\nSaruman :', s_avg_spell_power)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 6. Find the standard deviation of the spell power of Gandalf and Saruman. " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf: 15.132745950421556 \n", + "Saruman: 16.40629960309962\n" + ] + } + ], + "source": [ + "c=0\n", + "g=0\n", + "\n", + "for i in range(0,l):\n", + " a = g_spell_power[i]- g_avg_spell_power\n", + " b = a**2\n", + " c += b\n", + " \n", + "g_stdev = (c/l)**0.5\n", + "\n", + "for i in range(0,l):\n", + " e = s_spell_power[i]- s_avg_spell_power\n", + " f = e**2\n", + " g += f\n", + "\n", + "s_stdev = (g/(l-1))**0.5 \n", + "\n", + "print('Gandalf: ', g_stdev, '\\nSaruman: ', s_stdev)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb index b4a5f6d7e..aa6ae238b 100644 --- a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb +++ b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb @@ -49,10 +49,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandolf = [10, 11, 13, 30, 22, 11, 10, 33, 22, 22]\n", + "saruman = [23, 66, 12, 43, 12, 10, 44, 23, 12, 17]\n", + "spells =len(gandolf)\n" + ] }, { "cell_type": "markdown", @@ -64,10 +68,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandolf_wins =0\n", + "saruman_wins =0\n" + ] }, { "cell_type": "markdown", @@ -78,10 +85,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "for i in range(0,spells):\n", + " if gandolf[i] > saruman[i]:\n", + " gandolf_wins += 1\n", + " elif gandolf[i] < saruman[i]:\n", + " saruman_wins += 1\n", + "\n" + ] }, { "cell_type": "markdown", @@ -93,10 +107,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--- Gandalf wins ---\n" + ] + } + ], + "source": [ + "if (gandolf_wins > saruman_wins): \n", + " print(\"--- Gandalf wins ---\")\n", + "elif (saruman_wins > gandolf_wins ): \n", + " print(\"--- Saruman wins ---\")\n", + "else:\n", + " print(\"--- Tie ---\")\n" + ] }, { "cell_type": "markdown", @@ -128,10 +157,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "power = {'Fireball':50, 'Lightning bolt':40, 'Magic arrow': 10, 'Black Tentacles':25, 'Contagion':45}\n", + "\n", + "gandalf = ['Fireball', 'Lightning bolt', 'Lightning bolt', 'Magic arrow', 'Fireball', 'Magic arrow', \n", + " 'Lightning bolt', 'Fireball', 'Fireball', 'Fireball']\n", + "\n", + "saruman = ['Contagion', 'Contagion', 'Black Tentacles', 'Fireball', 'Black Tentacles','Lightning bolt',\n", + " 'Magic arrow', 'Contagion', 'Magic arrow', 'Magic arrow']" + ] }, { "cell_type": "markdown", @@ -142,10 +179,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins = 0\n", + "saruman_wins =0\n", + "\n" + ] }, { "cell_type": "markdown", @@ -156,10 +197,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_power = []\n", + "saruman_power =[]" + ] }, { "cell_type": "markdown", @@ -171,10 +215,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf is the winner\n", + "Gandalf is the winner\n" + ] + } + ], + "source": [ + "spells = list(power.keys())\n", + "spells_power = list(power.values())\n", + "\n", + "g_spell_power = []\n", + "s_spell_power = []\n", + "\n", + "l = len(gandalf)\n", + "p = len(power)\n", + "\n", + "for i in range(0, l):\n", + " for j in range(0,p):\n", + " if gandalf[i] == spells[j]:\n", + " g = spells_power[j]\n", + " g_spell_power.append(g) \n", + " \n", + "for i in range(0, l):\n", + " for j in range(0,p): \n", + " if saruman[i] == spells[j]:\n", + " s = spells_power[j]\n", + " s_spell_power.append(s)\n", + "\n", + "\n", + " \n", + "for i in range(0,l-2):\n", + " if (g_spell_power[i] > s_spell_power[i]) & (g_spell_power[i+1] > s_spell_power[i+1]) & (g_spell_power[i+2] > s_spell_power[i+2]):\n", + " print('Gandalf is the winner')\n", + " \n", + " elif (g_spell_power[i] < s_spell_power[i]) & (g_spell_power[i+1] < s_spell_power[i+1]) & (g_spell_power[i+2] < s_spell_power[i+2]):\n", + " print('Saruman is the winner')\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n" + ] }, { "cell_type": "markdown", @@ -185,10 +275,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf: 39.0 \n", + "Saruman : 30.5\n" + ] + } + ], + "source": [ + "g_avg_spell_power = sum(g_spell_power)/len(g_spell_power)\n", + "\n", + "s_avg_spell_power = sum(s_spell_power)/len(s_spell_power)\n", + " \n", + "print('Gandalf: ', g_avg_spell_power,'\\nSaruman :', s_avg_spell_power)\n", + "\n" + ] }, { "cell_type": "markdown", @@ -197,6 +303,48 @@ "#### 6. Find the standard deviation of the spell power of Gandalf and Saruman. " ] }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf: 15.132745950421556 \n", + "Saruman: 16.40629960309962\n" + ] + } + ], + "source": [ + "c=0\n", + "g=0\n", + "\n", + "for i in range(0,l):\n", + " a = g_spell_power[i]- g_avg_spell_power\n", + " b = a**2\n", + " c += b\n", + " \n", + "g_stdev = (c/l)**0.5\n", + "\n", + "for i in range(0,l):\n", + " e = s_spell_power[i]- s_avg_spell_power\n", + " f = e**2\n", + " g += f\n", + "\n", + "s_stdev = (g/(l-1))**0.5 \n", + "\n", + "print('Gandalf: ', g_stdev, '\\nSaruman: ', s_stdev)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -221,7 +369,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/1.-Python/3.-Bus/.ipynb_checkpoints/bus-checkpoint.ipynb b/1.-Python/3.-Bus/.ipynb_checkpoints/bus-checkpoint.ipynb new file mode 100644 index 000000000..4f430f697 --- /dev/null +++ b/1.-Python/3.-Bus/.ipynb_checkpoints/bus-checkpoint.ipynb @@ -0,0 +1,183 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "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": 2, + "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": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(stops)" + ] + }, + { + "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": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Passengers at each stop: [10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "passengers = []\n", + "n= 0\n", + "\n", + "for i in range(0,9):\n", + " n += stops[i][0] - stops[i][1]\n", + " passengers.append(n)\n", + "\n", + "print(\"Passengers at each stop:\" , passengers)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the maximum occupation of the bus." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max occupation: 14\n" + ] + } + ], + "source": [ + "print(\"Max occupation: \", max(passengers))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Calculate the average occupation. And the standard deviation." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Average occupation: 9\n" + ] + } + ], + "source": [ + "avg = int(sum(passengers)/9)\n", + "print (\" Average occupation:\", avg)" + ] + }, + { + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/3.-Bus/bus.ipynb b/1.-Python/3.-Bus/bus.ipynb index 31f09b8fd..69ddb0351 100644 --- a/1.-Python/3.-Bus/bus.ipynb +++ b/1.-Python/3.-Bus/bus.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -52,10 +52,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(stops)" + ] }, { "cell_type": "markdown", @@ -67,10 +80,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Passengers at each stop: [10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "passengers = []\n", + "n= 0\n", + "\n", + "for i in range(0,9):\n", + " n += stops[i][0] - stops[i][1]\n", + " passengers.append(n)\n", + "\n", + "print(\"Passengers at each stop:\" , passengers)" + ] }, { "cell_type": "markdown", @@ -81,10 +111,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max occupation: 14\n" + ] + } + ], + "source": [ + "print(\"Max occupation: \", max(passengers))" + ] }, { "cell_type": "markdown", @@ -95,10 +135,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Average occupation: 9\n" + ] + } + ], + "source": [ + "avg = int(sum(passengers)/9)\n", + "print (\" Average occupation:\", avg)" + ] } ], "metadata": { @@ -117,7 +168,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/1.-Python/4.-Robin-Hood/.ipynb_checkpoints/robin-hood-checkpoint.ipynb b/1.-Python/4.-Robin-Hood/.ipynb_checkpoints/robin-hood-checkpoint.ipynb new file mode 100644 index 000000000..5e03a700c --- /dev/null +++ b/1.-Python/4.-Robin-Hood/.ipynb_checkpoints/robin-hood-checkpoint.ipynb @@ -0,0 +1,226 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Robin Hood\n", + "Robin Hood has entered a competition to win the archery contest in Sherwood. With his bow and arrows, he needs to shoot on a target and try to hit as close as possible to the center.\n", + "\n", + "![](images/arrows.jpg)\n", + "\n", + "## Context\n", + "In this challenge, the landing position of arrows shot by archers in the competition will be represented using 2-dimensional coordinates. \n", + "\n", + "In the 2-dimensional space, a point can be defined by a pair of values that correspond to the horizontal coordinate (x) and the vertical coordinate (y). For example, in our case, an arrow that hits the center of the archery target will land in position (0, 0) on the coordinate axes. \n", + "\n", + "The space can be divided into 4 zones (quadrants): Q1, Q2, Q3, Q4. If a point is in Q1, both its x coordinate and y coordinate are positive. Any point with a null x or y coordinate is considered to not belong to any quadrant. \n", + "\n", + "If you want to know more about the cartesian coordinate system, you can check this [link](https://en.wikipedia.org/wiki/Cartesian_coordinate_system). \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, sets, tuples**\n", + "* Conditional statements: **if-elif-else**\n", + "* Loop: **while/for**\n", + "* Minimum (optional sorting)\n", + "\n", + "## Tasks\n", + "Robin Hood has hit the following points:" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [], + "source": [ + "points = [(4, 5), (-0, 2), (4, 7), (1, -3), (3, -2), (4, 5), (3, 2), (5, 7), (-5, 7), (2, 2), (-4, 5), (0, -2),\n", + " (-4, 7), (-1, 3), (-3, 2), (-4, -5), (-3, 2), (5, 7), (5, 7), (2, 2), (9, 9), (-8, -9)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 1. Robin Hood is famous for hitting an arrow with another arrow. Find the coordinates of the points where an arrow hits another arrow." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{(-3, 2), (4, 5), (5, 7), (2, 2)}\n" + ] + } + ], + "source": [ + "points.sort()\n", + "ar_w_ar =[]\n", + "\n", + "for i in range(0, (len(points)-1)):\n", + " if points[i] == points[i+1]:\n", + " ar_w_ar.append(points[i])\n", + " \n", + "print(set(ar_w_ar))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " #### 2. Calculate how many arrows have fallen in each quadrant. \n", + "**Note**: the arrows that fall in the axis (x=0 or y=0) don't belong to any quadrant." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "arrows fallen in Q1: 10 \n", + "arrows fallen in Q2: 6 \n", + "arrows fallen in Q3: 2 \n", + "arrows fallen in Q4: 2\n" + ] + } + ], + "source": [ + "Q1 = 0\n", + "Q2 = 0\n", + "Q3 = 0\n", + "Q4 = 0\n", + "\n", + "for i in range (0, len(points)):\n", + " if (points[i][0] < 0) & (points[i][1] < 0):\n", + " Q3 += 1\n", + " elif (points[i][0] < 0) & (points[i][1] > 0):\n", + " Q2 += 1\n", + " elif (points[i][0] > 0) & (points[i][1]< 0):\n", + " Q4 += 1\n", + " elif (points[i][0] > 0) & (points[i][1]> 0):\n", + " Q1 += 1\n", + "\n", + "print (\"arrows fallen in Q1: \", Q1,\"\\narrows fallen in Q2: \", Q2, \"\\narrows fallen in Q3: \", Q3, \"\\narrows fallen in Q4: \", Q4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the point closest to the center. Calculate its distance to the center. \n", + "Take into account that there might be more than one point at the minimum distance to the center.\n", + "\n", + "**Hint**: Use the Euclidean distance. You can find more information about it [here](https://en.wikipedia.org/wiki/Euclidean_distance). \n", + "**Hint**: Defining a function that calculates the distance to the center can help." + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The point (0, 2) has the min distance from the center: 2.0\n", + "The point (0, -2) has the min distance from the center: 2.0\n" + ] + } + ], + "source": [ + "def distance(x,y):\n", + " return (x**2+y**2)**0.5\n", + "\n", + "d = []\n", + "\n", + "for i in range(0, len(points)):\n", + " a = distance(points[i][0], points[i][1])\n", + " d.append(a)\n", + "\n", + " \n", + "for i in range(0, len(points)):\n", + " if d[i] == min(d):\n", + " print(\"The point\",(points[i][0], points[i][1]), \"has the min distance from the center: \", d[i])\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. If the archery target has a radius of 9, calculate the number of arrows that won't hit the target. \n", + "**Hint**: Use the function created in step 3. " + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 arrows won't hit the target\n" + ] + } + ], + "source": [ + "no_target = 0\n", + "\n", + "for i in range(0, len(points)):\n", + " if d[i] > 9:\n", + " no_target +=1\n", + "\n", + "print(no_target, \"arrows won't hit the target\")" + ] + } + ], + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/4.-Robin-Hood/robin-hood.ipynb b/1.-Python/4.-Robin-Hood/robin-hood.ipynb index 01de29d3b..5e03a700c 100644 --- a/1.-Python/4.-Robin-Hood/robin-hood.ipynb +++ b/1.-Python/4.-Robin-Hood/robin-hood.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, "outputs": [], "source": [ @@ -55,25 +55,70 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{(-3, 2), (4, 5), (5, 7), (2, 2)}\n" + ] + } + ], + "source": [ + "points.sort()\n", + "ar_w_ar =[]\n", + "\n", + "for i in range(0, (len(points)-1)):\n", + " if points[i] == points[i+1]:\n", + " ar_w_ar.append(points[i])\n", + " \n", + "print(set(ar_w_ar))\n" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### 2. Calculate how many arrows have fallen in each quadrant. \n", + " #### 2. Calculate how many arrows have fallen in each quadrant. \n", "**Note**: the arrows that fall in the axis (x=0 or y=0) don't belong to any quadrant." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "arrows fallen in Q1: 10 \n", + "arrows fallen in Q2: 6 \n", + "arrows fallen in Q3: 2 \n", + "arrows fallen in Q4: 2\n" + ] + } + ], + "source": [ + "Q1 = 0\n", + "Q2 = 0\n", + "Q3 = 0\n", + "Q4 = 0\n", + "\n", + "for i in range (0, len(points)):\n", + " if (points[i][0] < 0) & (points[i][1] < 0):\n", + " Q3 += 1\n", + " elif (points[i][0] < 0) & (points[i][1] > 0):\n", + " Q2 += 1\n", + " elif (points[i][0] > 0) & (points[i][1]< 0):\n", + " Q4 += 1\n", + " elif (points[i][0] > 0) & (points[i][1]> 0):\n", + " Q1 += 1\n", + "\n", + "print (\"arrows fallen in Q1: \", Q1,\"\\narrows fallen in Q2: \", Q2, \"\\narrows fallen in Q3: \", Q3, \"\\narrows fallen in Q4: \", Q4)" + ] }, { "cell_type": "markdown", @@ -88,10 +133,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The point (0, 2) has the min distance from the center: 2.0\n", + "The point (0, -2) has the min distance from the center: 2.0\n" + ] + } + ], + "source": [ + "def distance(x,y):\n", + " return (x**2+y**2)**0.5\n", + "\n", + "d = []\n", + "\n", + "for i in range(0, len(points)):\n", + " a = distance(points[i][0], points[i][1])\n", + " d.append(a)\n", + "\n", + " \n", + "for i in range(0, len(points)):\n", + " if d[i] == min(d):\n", + " print(\"The point\",(points[i][0], points[i][1]), \"has the min distance from the center: \", d[i])\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n" + ] }, { "cell_type": "markdown", @@ -103,10 +180,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 arrows won't hit the target\n" + ] + } + ], + "source": [ + "no_target = 0\n", + "\n", + "for i in range(0, len(points)):\n", + " if d[i] > 9:\n", + " no_target +=1\n", + "\n", + "print(no_target, \"arrows won't hit the target\")" + ] } ], "metadata": { @@ -125,7 +218,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/1.-Python/5.-Temperature-Processor/.ipynb_checkpoints/temperature-checkpoint.ipynb b/1.-Python/5.-Temperature-Processor/.ipynb_checkpoints/temperature-checkpoint.ipynb new file mode 100644 index 000000000..661c8081e --- /dev/null +++ b/1.-Python/5.-Temperature-Processor/.ipynb_checkpoints/temperature-checkpoint.ipynb @@ -0,0 +1,454 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Temperature Sensor\n", + "\n", + "There is a temperature sensor in the processor of your company's server. The company wants to analyze the data provided by the sensor to decide if they should change the cooling system for a better one. As changing the cooling system is expensive and you are an excellent data analyst, you can't make a decision without basis.\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", + "1. Data structures: **lists**\n", + "2. Loops: **list comprehension**\n", + "3. Functions: **min, max, print, len**\n", + "4. Conditional statements: **if-elif-else**\n", + "\n", + "## Tasks\n", + "The temperatures measured throughout the 24 hours of a day are:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "temperatures_C = [33, 66, 65, 0, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The first element of the list is the temperature at 12am, the second element is the temperature at 1am, and so on. \n", + "\n", + "The company has decided that if one of the following events occurs, then the cooling system needs to be replaced for a new one to avoid damaging the processor.\n", + "* More than 4 temperatures are greater than or equal to 70ºC.\n", + "* Any temperature is above 80ºC.\n", + "* The average temperature exceeds 65ºC.\n", + "\n", + "Follow the steps so that you can make the decision.\n", + "\n", + "#### 1. Find the minimum temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " min Temp: 0\n" + ] + } + ], + "source": [ + "mi = min(temperatures_C)\n", + "print(\" min Temp: \", mi)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Find the maximum temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " max Temp: 90\n" + ] + } + ], + "source": [ + "ma = max(temperatures_C)\n", + "print(\" max Temp: \", ma )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Create a list with the temperatures that are greater than or equal to 70ºC. Store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[70, 76, 80, 81, 80, 83, 90, 79]\n" + ] + } + ], + "source": [ + "T_over = []\n", + "\n", + "for i in range(0, len(temperatures_C)):\n", + " if temperatures_C[i] >= 70:\n", + " T_over.append(temperatures_C[i])\n", + "\n", + "print(T_over)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Find the average temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average temperature: 60.25\n" + ] + } + ], + "source": [ + "avg_T = sum(temperatures_C)/len(temperatures_C)\n", + "\n", + "print(\"average temperature: \", avg_T)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5. Imagine that there was a sensor failure at 3am and the data for that specific hour was not recorded. How would you estimate the missing value? Replace the current value of the list at 3am for an estimation. " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[33, 66, 65, 62, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n" + ] + } + ], + "source": [ + "T_three_am = (temperatures_C[2] + temperatures_C[4])/2\n", + "\n", + "temperatures_C.remove(0)\n", + "temperatures_C.insert(3,int(T_three_am))\n", + "print(temperatures_C)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 6. Bonus: the maintenance staff is from the United States and does not understand the international metric system. Help them by converting the temperatures from Celsius to Fahrenheit.\n", + "To know more about temperature conversion check this [link](https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature).\n", + "\n", + "**Formula**: \n", + "\n", + "$F = 1.8 * C + 32$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[91.4, 150.8, 149.0, 143.60000000000002, 138.2, 140.0, 143.60000000000002, 147.2, 158.0, 168.8, 176.0, 177.8, 176.0, 181.4, 194.0, 174.20000000000002, 141.8, 127.4, 122.0, 120.2, 127.4, 118.4, 113.0, 102.2]\n" + ] + } + ], + "source": [ + "def conversion(T):\n", + " return 1.8*T + 32\n", + "\n", + "temperature_F = []\n", + "\n", + "for i in range(0,len(temperatures_C)):\n", + " a = conversion(temperatures_C[i])\n", + " temperature_F.append(a)\n", + "\n", + "print(temperature_F)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 7. Make a decision!\n", + "Now it's time to make a decision taking into account what you have seen until now. \n", + "\n", + "Remember that if one of the following events occurs, then the cooling system needs to be replaced for a new one to avoid damaging the processor.\n", + "* More than 4 temperatures are greater than or equal to 70ºC.\n", + "* Any temperature is above 80ºC.\n", + "* The average temperature exceeds 65ºC.\n", + "\n", + "#### To make your decision, check if any of the three conditions above is met. You might need to use some of the variables you created in steps 1 to 6. Print a message to show if the cooling system needs to be changed or not." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "!!! The cooling system needs to be changed !!!\n" + ] + } + ], + "source": [ + "if (avg_T > 65) | (len(T_over) >= 4) | (ma >= 80):\n", + " print(\"!!! The cooling system needs to be changed !!!\")\n", + "else:\n", + " print(\"The cooling system doesn't need to be changed \")\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus\n", + "\n", + "The company has decided that the decision you made is not valid. They want you to analyze the data again but this time, the conditions that need to be met in order to change the cooling system are different.\n", + "\n", + "This time, if one of the following events occurs, then the cooling system needs to be replaced:\n", + "* The temperature is greater than 70ºC during more than 4 consecutive hours.\n", + "* Any temperature is above 80ºC.\n", + "* The average temperature exceeds 65ºC.\n", + "\n", + "Follow the steps so that you can make the decision.\n", + "\n", + "#### 1. Create a list with the hours where the temperature is greater than 70ºC. Store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 10, 11, 12, 13, 14, 15]\n" + ] + } + ], + "source": [ + "hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ,22, 23]\n", + "\n", + "hours_over_T= []\n", + "\n", + "for i in range(0, len(hours)):\n", + " if temperatures_C[i] > 70:\n", + " a = hours[i]\n", + " hours_over_T.append(a)\n", + "\n", + "print(hours_over_T) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Check if the list you created in step 1 has more than 4 consecutive hours. " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "a= 0\n", + "\n", + "for i in range(0,len(hours_over_T)-1):\n", + " if hours_over_T[i] == hours_over_T[i+1] -1:\n", + " a+= 1\n", + " else:\n", + " a = 0\n", + " if a >= 4:\n", + " b = a\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Make the decision!\n", + "To make your decision, check if any of the three conditions is met. Print a message to show if the cooling system needs to be changed or not." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "!!! The cooling system needs to be changed !!!\n" + ] + } + ], + "source": [ + "if (avg_T > 65) | (ma >= 80) | (b >= 4) :\n", + " print(\"!!! The cooling system needs to be changed !!!\")\n", + "else:\n", + " print(\"The cooling system doesn't need to be changed \")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Find the average value of the temperature lists (ºC and ºF). What is the relation between both average values?" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average T:\n", + " 62.833333333333336 Celsius\n", + " 145.1 Fahrenheit\n" + ] + } + ], + "source": [ + "T_avg_C = sum(temperatures_C)/len(temperatures_C) \n", + "T_avg_F = sum(temperature_F)/len(temperature_F)\n", + "\n", + "print('Average T:\\n',T_avg_C, 'Celsius\\n', T_avg_F, 'Fahrenheit')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5. Find the standard deviation of the temperature lists (ºC and ºF). What is the relation between both standard deviations?" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Standard deviation T:\n", + " 14.94821980579356 Celsius\n", + " 26.906795650428407 Fahrenheit\n" + ] + } + ], + "source": [ + "c = 0\n", + "f = 0\n", + "\n", + "for i in range(0, len(temperatures_C)):\n", + " a = temperatures_C[i] - T_avg_C\n", + " b = a**2\n", + " c += b \n", + " \n", + " d = temperature_F[i] - T_avg_F\n", + " e = d**2\n", + " f += e\n", + "\n", + "T_stdev_C = (c/(len(temperatures_C)-1))**0.5\n", + "T_stdev_F = (f/(len(temperatures_C)-1))**0.5\n", + "\n", + "print('Standard deviation T:\\n',T_stdev_C , 'Celsius\\n', T_stdev_F, 'Fahrenheit')" + ] + }, + { + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/5.-Temperature-Processor/temperature.ipynb b/1.-Python/5.-Temperature-Processor/temperature.ipynb index 4b597aa20..661c8081e 100644 --- a/1.-Python/5.-Temperature-Processor/temperature.ipynb +++ b/1.-Python/5.-Temperature-Processor/temperature.ipynb @@ -28,11 +28,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "temperatures_C = [33, 66, 65, 0, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]" + "temperatures_C = [33, 66, 65, 0, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n", + "\n", + "\n" ] }, { @@ -53,10 +55,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " min Temp: 0\n" + ] + } + ], + "source": [ + "mi = min(temperatures_C)\n", + "print(\" min Temp: \", mi)" + ] }, { "cell_type": "markdown", @@ -67,10 +80,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " max Temp: 90\n" + ] + } + ], + "source": [ + "ma = max(temperatures_C)\n", + "print(\" max Temp: \", ma )" + ] }, { "cell_type": "markdown", @@ -81,10 +105,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[70, 76, 80, 81, 80, 83, 90, 79]\n" + ] + } + ], + "source": [ + "T_over = []\n", + "\n", + "for i in range(0, len(temperatures_C)):\n", + " if temperatures_C[i] >= 70:\n", + " T_over.append(temperatures_C[i])\n", + "\n", + "print(T_over)" + ] }, { "cell_type": "markdown", @@ -95,10 +135,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average temperature: 60.25\n" + ] + } + ], + "source": [ + "avg_T = sum(temperatures_C)/len(temperatures_C)\n", + "\n", + "print(\"average temperature: \", avg_T)" + ] }, { "cell_type": "markdown", @@ -109,10 +161,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[33, 66, 65, 62, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n" + ] + } + ], + "source": [ + "T_three_am = (temperatures_C[2] + temperatures_C[4])/2\n", + "\n", + "temperatures_C.remove(0)\n", + "temperatures_C.insert(3,int(T_three_am))\n", + "print(temperatures_C)\n" + ] }, { "cell_type": "markdown", @@ -123,15 +189,35 @@ "\n", "**Formula**: \n", "\n", - "$F = 1.8 * C + 32$" + "$F = 1.8 * C + 32$\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[91.4, 150.8, 149.0, 143.60000000000002, 138.2, 140.0, 143.60000000000002, 147.2, 158.0, 168.8, 176.0, 177.8, 176.0, 181.4, 194.0, 174.20000000000002, 141.8, 127.4, 122.0, 120.2, 127.4, 118.4, 113.0, 102.2]\n" + ] + } + ], + "source": [ + "def conversion(T):\n", + " return 1.8*T + 32\n", + "\n", + "temperature_F = []\n", + "\n", + "for i in range(0,len(temperatures_C)):\n", + " a = conversion(temperatures_C[i])\n", + " temperature_F.append(a)\n", + "\n", + "print(temperature_F)\n", + " " + ] }, { "cell_type": "markdown", @@ -150,10 +236,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "!!! The cooling system needs to be changed !!!\n" + ] + } + ], + "source": [ + "if (avg_T > 65) | (len(T_over) >= 4) | (ma >= 80):\n", + " print(\"!!! The cooling system needs to be changed !!!\")\n", + "else:\n", + " print(\"The cooling system doesn't need to be changed \")\n", + "\n", + "\n" + ] }, { "cell_type": "markdown", @@ -175,10 +276,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 10, 11, 12, 13, 14, 15]\n" + ] + } + ], + "source": [ + "hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ,22, 23]\n", + "\n", + "hours_over_T= []\n", + "\n", + "for i in range(0, len(hours)):\n", + " if temperatures_C[i] > 70:\n", + " a = hours[i]\n", + " hours_over_T.append(a)\n", + "\n", + "print(hours_over_T) " + ] }, { "cell_type": "markdown", @@ -189,10 +309,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "a= 0\n", + "\n", + "for i in range(0,len(hours_over_T)-1):\n", + " if hours_over_T[i] == hours_over_T[i+1] -1:\n", + " a+= 1\n", + " else:\n", + " a = 0\n", + " if a >= 4:\n", + " b = a\n" + ] }, { "cell_type": "markdown", @@ -204,10 +334,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "!!! The cooling system needs to be changed !!!\n" + ] + } + ], + "source": [ + "if (avg_T > 65) | (ma >= 80) | (b >= 4) :\n", + " print(\"!!! The cooling system needs to be changed !!!\")\n", + "else:\n", + " print(\"The cooling system doesn't need to be changed \")" + ] }, { "cell_type": "markdown", @@ -218,10 +361,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average T:\n", + " 62.833333333333336 Celsius\n", + " 145.1 Fahrenheit\n" + ] + } + ], + "source": [ + "T_avg_C = sum(temperatures_C)/len(temperatures_C) \n", + "T_avg_F = sum(temperature_F)/len(temperature_F)\n", + "\n", + "print('Average T:\\n',T_avg_C, 'Celsius\\n', T_avg_F, 'Fahrenheit')" + ] }, { "cell_type": "markdown", @@ -230,6 +388,40 @@ "#### 5. Find the standard deviation of the temperature lists (ºC and ºF). What is the relation between both standard deviations?" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Standard deviation T:\n", + " 14.94821980579356 Celsius\n", + " 26.906795650428407 Fahrenheit\n" + ] + } + ], + "source": [ + "c = 0\n", + "f = 0\n", + "\n", + "for i in range(0, len(temperatures_C)):\n", + " a = temperatures_C[i] - T_avg_C\n", + " b = a**2\n", + " c += b \n", + " \n", + " d = temperature_F[i] - T_avg_F\n", + " e = d**2\n", + " f += e\n", + "\n", + "T_stdev_C = (c/(len(temperatures_C)-1))**0.5\n", + "T_stdev_F = (f/(len(temperatures_C)-1))**0.5\n", + "\n", + "print('Standard deviation T:\\n',T_stdev_C , 'Celsius\\n', T_stdev_F, 'Fahrenheit')" + ] + }, { "cell_type": "code", "execution_count": null, @@ -254,7 +446,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/.ipynb_checkpoints/rock-paper-scissors-checkpoint.ipynb" "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/.ipynb_checkpoints/rock-paper-scissors-checkpoint.ipynb" new file mode 100644 index 000000000..6c1c92051 --- /dev/null +++ "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/.ipynb_checkpoints/rock-paper-scissors-checkpoint.ipynb" @@ -0,0 +1,572 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Rock, Paper & Scissors\n", + "\n", + "Let's play the famous game against our computer. You can check the rules [here](https://en.wikipedia.org/wiki/Rock%E2%80%93paper%E2%80%93scissors). \n", + "\n", + "## Task\n", + "Create a program that imitates the playability of the well known game of rock, paper, scissors. Follow the guidelines provided.\n", + "\n", + "## Tools\n", + "1. Loop: **for/while**\n", + "2. Functions: **input(), print()...**\n", + "3. Conditional statements: **if, elif, else**\n", + "4. Definition of functions. Modular programming\n", + "5. Import modules\n", + "\n", + "**To solve this challenge, the use of functions is recommended.**\n", + "\n", + "#### 1. Import the choice function of the random module." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "\n", + "# Rafa's solution\n", + "#from random import choice" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Create a list that includes the 3 possible gesture options of the game: 'rock', 'paper' or 'scissors'. Store the list in a variable called `gestures`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "gestures = ['rock', 'paper', 'scissors']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Create a variable called `n_rounds` to store the maximum number of rounds to play in a game. \n", + "Remember that the number of rounds must be odd: 1, 3, 5, ..." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "n_rounds = 3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Create a variable called `rounds_to_win` to store the number of rounds that a player must win to win the game.\n", + "**Hint**: the value stored in `rounds_to_win` depends on the value of `n_rounds`. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "rounds_to_win = int(n_rounds/2) + 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5. Create two variables to store the number of rounds that the computer and the player have won. Call these variables `cpu_score` and `player_score`." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "cpu_score = 0\n", + "player_score = 0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 6. Define a function that randomly returns one of the 3 gesture options.\n", + "You will use this function to simulate the gesture choice of the computer. " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def ran_ges():\n", + " return random.choice(gestures) \n", + "\n", + "# Rafa's solution:\n", + "# def cpu_choice():\n", + "# return choice(gestures)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 7. Define a function that asks the player which is the gesture he or she wants to show: 'rock', 'paper' or 'scissors'.\n", + "The player should only be allowed to choose one of the 3 gesture options. If the player's choice is not rock, paper or scissors, keep asking until it is." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def pl_ges():\n", + " a= input()\n", + " if (a == 'rock') |(a == 'paper') | (a == 'scissors'):\n", + " return a\n", + " else:\n", + " b=input()\n", + " return b\n", + "\n", + "# Rafa's solution: \n", + "#def player_choice():\n", + "# print(\"\\nplease enter one of the choices:\", gestures)\n", + "# while(True):\n", + "# player_input = input() \n", + "# player_input in gestures: break\n", + "# return player_input" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 8. Define a function that checks who won a round. \n", + "The function should return 0 if there is a tie, 1 if the computer wins and 2 if the player wins.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "def decision(c, p):\n", + " \n", + " if (c == 'rock') & (p == 'paper'):\n", + " a = 2\n", + " \n", + " elif (c == 'paper') & (p == 'rock'):\n", + " a = 1\n", + " \n", + " elif (c == 'rock') & (p == 'scissors'):\n", + " a = 1\n", + " \n", + " elif (c == 'scissors') & (p == 'rock'):\n", + " a = 2\n", + " \n", + " elif (c == 'paper') & (p == 'scissors'):\n", + " a = 2\n", + " \n", + " elif (c == 'scissors') & (p == 'paper'):\n", + " a = 1\n", + " \n", + " else:\n", + " a = 0\n", + " \n", + " \n", + " return a \n", + "\n", + "# Rafa's solution:\n", + "#def winner (cpu_choice,player_choice):\n", + "# if(cpu_choice == player_choice): return 0\n", + "# elif cpu_choice == 'rock':\n", + "# if (player_choice == 'scissors'): return 1 \n", + "# else: return 2 ##player wins\n", + "# elif cpu_choice == 'scissors': \n", + "# if (player_choice == 'rock'): return 2 \n", + "# else: return 1 ##computer wins\n", + "# else: ## computer choice is paper\n", + "# if(player_choice == 'scissors'): return 2\n", + "# else: return 1 ##computer wins\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 9. Define a function that prints the choice of the computer, the choice of the player and a message that announces who won the current round. \n", + "You should also use this function to update the variables that count the number of rounds that the computer and the player have won. The score of the winner increases by one point. If there is a tie, the score does not increase." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "def announcement ():\n", + "\n", + " print('choice of player: ', player, '\\nchoice of computer: ', cpu)\n", + " \n", + " if dis == 1:\n", + " print('computer wins')\n", + " \n", + " elif dis == 2:\n", + " print('player wins')\n", + " \n", + " else:\n", + " print('Tie') \n", + " \n", + " return\n", + "\n", + "\n", + "## Rafa's solution:\n", + "## def round_results():\n", + "## p_choice = player_choice()\n", + "## print('\\nplayer choice is', p_choice)\n", + "\n", + "## cp_choice = cpu_choice()\n", + "## print('\\nplayer choice is', cpu_choice)\n", + "## winning_round = winner(cpu_choice, p_choice)\n", + "## \n", + "## print('the winner is', winning round)\n", + "## global n_rounds, player_score, cpu_score\n", + "## n_rounds = n_rounds + 1\n", + "## if winning_round == 1: cpu_score = cpu_score + 1\n", + "## if winning_round == 2: player_score = player_score + 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 10. Now it's time to code the execution of the game using the functions and variables you defined above. \n", + "\n", + "First, create a loop structure that repeats while no player reaches the minimum score necessary to win and the number of rounds is less than the maximum number of rounds to play in a game. \n", + "\n", + "Inside the loop, use the functions and variables above to create the execution of a round: ask for the player's choice, generate the random choice of the computer, show the round results, update the scores, etc. " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rock\n", + "choice of player: rock \n", + "choice of computer: paper\n", + "computer wins\n", + "\n", + "\n", + "paper\n", + "choice of player: paper \n", + "choice of computer: scissors\n", + "computer wins\n", + "\n", + "\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: rock\n", + "Tie\n", + "\n", + "\n", + "player score: 0 in 3 \n", + "computer score: 2 in 3\n" + ] + } + ], + "source": [ + "for i in range(0, n_rounds): \n", + " \n", + " cpu = ran_ges()\n", + " player = pl_ges()\n", + " \n", + " dis = decision(cpu, player)\n", + " if dis == 1:\n", + " cpu_score += 1\n", + " elif dis == 2:\n", + " player_score +=1\n", + " \n", + " announcement()\n", + " print('\\n') \n", + " \n", + "print('player score: ', player_score, ' in ', n_rounds, '\\ncomputer score: ', cpu_score, ' in ', n_rounds ) \n", + "\n", + "\n", + "# Rafa's solution:\n", + "#n_rounds = 0\n", + "#cpu_score, player_score = 0\n", + "#rounds_to_win = 3\n", + "\n", + "# while(cpu_score < rounds_to_win and player_score < rounds_to_win <7):\n", + "# round_results() " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 11. Print the winner of the game based on who won more rounds.\n", + "Remember that the game might be tied. " + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computer is the final winner\n" + ] + } + ], + "source": [ + "if cpu_score > player_score:\n", + " print('Computer is the final winner')\n", + "\n", + "elif player_score > cpu_score:\n", + " print('Player is the final winner')\n", + "\n", + "else:\n", + " print('The game ended in a tie')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bonus: Rock, Paper, Scissors, Lizard & Spock\n", + "![](images/rpsls.jpg)\n", + "\n", + "In this challenge, you need to improve the previous game by adding two new options. To know more about the rules of the improved version of rock, paper, scissors, check this [link](http://www.samkass.com/theories/RPSSL.html). \n", + "\n", + "In addition, you will also need to improve how the game interacts with the player: the number of rounds to play, which must be an odd number, will be requested to the user until a valid number is entered. Define a new function to make that request.\n", + "\n", + "**Hint**: Try to reuse the code that you already coded in the previous challenge. If your code is efficient, this bonus will only consist of simple modifications to the original game." + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "please enter a number of rounds: 3\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: scissors\n", + "player wins\n", + "\n", + "\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: lizard\n", + "player wins\n", + "\n", + "\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: rock\n", + "Tie\n", + "\n", + "\n", + "player score: 2 in \n", + "computer score: 0 in \n", + "Player is the final winner\n" + ] + } + ], + "source": [ + "import random\n", + "\n", + "gestures = ['rock', 'paper', 'scissors', 'lizard', 'spock']\n", + "\n", + "# definition of number of rounds\n", + "def n_rounds():\n", + " n = int(input('please enter a number of rounds: '))\n", + " if n%2 == 1:\n", + " return n\n", + " else:\n", + " print('enter an odd number: ')\n", + " n_rounds()\n", + " \n", + "\n", + "cpu_score = 0\n", + "player_score = 0\n", + "\n", + "\n", + "# Computer's choice:\n", + "def ran_ges():\n", + " return random.choice(gestures) \n", + "\n", + "\n", + "# Player's choice:\n", + "def pl_ges():\n", + " while(True):\n", + " a = input() \n", + " a in gestures; break \n", + " return a\n", + " \n", + " \n", + "# def player_choice():\n", + " while(True):\n", + " player_input = input() \n", + " player_input in gestures; break\n", + " return player_input \n", + "\n", + "\n", + "# Decision on the game results:\n", + "def decision(c, p):\n", + "\n", + " if c == p :\n", + " return 0 \n", + " elif c == 'paper':\n", + " if (p == 'rock') or (p == 'spock'):\n", + " return 1\n", + " else:\n", + " return 2\n", + " elif c == 'scissors':\n", + " if (p == 'paper') or (p == 'lizard'):\n", + " return 1\n", + " else:\n", + " return 2\n", + " elif c == 'lizard':\n", + " if (p == 'paper') or (p == 'spock'):\n", + " return 1\n", + " else:\n", + " return 2 \n", + " elif c == 'spock':\n", + " if (p == 'scissors') or (p == 'rock'):\n", + " return 1\n", + " else:\n", + " return 2 \n", + " else:\n", + " if (p == 'scissors') or (p == 'lizard'):\n", + " return 1\n", + " else:\n", + " return 2 \n", + " \n", + "\n", + "# announcement who is the winner\n", + "def announcement ():\n", + "\n", + " print('choice of player: ', player, '\\nchoice of computer: ', cpu)\n", + " \n", + " if dis == 1:\n", + " print('computer wins')\n", + " elif dis == 2:\n", + " print('player wins')\n", + " else:\n", + " print('Tie') \n", + " \n", + " return\n", + "\n", + "\n", + "# start to playing game\n", + "\n", + "l = int(n_rounds())\n", + "\n", + "for i in range(0,l): \n", + " \n", + " cpu = ran_ges()\n", + " player = pl_ges()\n", + " \n", + " dis = decision(cpu, player)\n", + " if dis == 1:\n", + " cpu_score += 1\n", + " elif dis == 2:\n", + " player_score +=1\n", + " \n", + " announcement()\n", + " print('\\n') \n", + " \n", + "print('player score: ', player_score, ' in ', n_rounds, '\\ncomputer score: ', cpu_score, ' in ', n_rounds ) \n", + "\n", + "\n", + "\n", + "# decising on final winner\n", + "if cpu_score > player_score:\n", + " print('Computer is the final winner')\n", + "\n", + "elif player_score > cpu_score:\n", + " print('Player is the final winner')\n", + "\n", + "else:\n", + " print('The game ended in a tie')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" index 9e551dfd4..6c1c92051 100644 --- "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" +++ "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" @@ -32,10 +32,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import random\n", + "\n", + "# Rafa's solution\n", + "#from random import choice" + ] }, { "cell_type": "markdown", @@ -46,10 +51,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gestures = ['rock', 'paper', 'scissors']" + ] }, { "cell_type": "markdown", @@ -61,10 +68,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "n_rounds = 3" + ] }, { "cell_type": "markdown", @@ -76,10 +85,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "rounds_to_win = int(n_rounds/2) + 1" + ] }, { "cell_type": "markdown", @@ -90,10 +101,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "cpu_score = 0\n", + "player_score = 0" + ] }, { "cell_type": "markdown", @@ -105,10 +119,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def ran_ges():\n", + " return random.choice(gestures) \n", + "\n", + "# Rafa's solution:\n", + "# def cpu_choice():\n", + "# return choice(gestures)" + ] }, { "cell_type": "markdown", @@ -120,25 +141,80 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def pl_ges():\n", + " a= input()\n", + " if (a == 'rock') |(a == 'paper') | (a == 'scissors'):\n", + " return a\n", + " else:\n", + " b=input()\n", + " return b\n", + "\n", + "# Rafa's solution: \n", + "#def player_choice():\n", + "# print(\"\\nplease enter one of the choices:\", gestures)\n", + "# while(True):\n", + "# player_input = input() \n", + "# player_input in gestures: break\n", + "# return player_input" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 8. Define a function that checks who won a round. \n", - "The function should return 0 if there is a tie, 1 if the computer wins and 2 if the player wins." + "The function should return 0 if there is a tie, 1 if the computer wins and 2 if the player wins.\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def decision(c, p):\n", + " \n", + " if (c == 'rock') & (p == 'paper'):\n", + " a = 2\n", + " \n", + " elif (c == 'paper') & (p == 'rock'):\n", + " a = 1\n", + " \n", + " elif (c == 'rock') & (p == 'scissors'):\n", + " a = 1\n", + " \n", + " elif (c == 'scissors') & (p == 'rock'):\n", + " a = 2\n", + " \n", + " elif (c == 'paper') & (p == 'scissors'):\n", + " a = 2\n", + " \n", + " elif (c == 'scissors') & (p == 'paper'):\n", + " a = 1\n", + " \n", + " else:\n", + " a = 0\n", + " \n", + " \n", + " return a \n", + "\n", + "# Rafa's solution:\n", + "#def winner (cpu_choice,player_choice):\n", + "# if(cpu_choice == player_choice): return 0\n", + "# elif cpu_choice == 'rock':\n", + "# if (player_choice == 'scissors'): return 1 \n", + "# else: return 2 ##player wins\n", + "# elif cpu_choice == 'scissors': \n", + "# if (player_choice == 'rock'): return 2 \n", + "# else: return 1 ##computer wins\n", + "# else: ## computer choice is paper\n", + "# if(player_choice == 'scissors'): return 2\n", + "# else: return 1 ##computer wins\n" + ] }, { "cell_type": "markdown", @@ -150,10 +226,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def announcement ():\n", + "\n", + " print('choice of player: ', player, '\\nchoice of computer: ', cpu)\n", + " \n", + " if dis == 1:\n", + " print('computer wins')\n", + " \n", + " elif dis == 2:\n", + " print('player wins')\n", + " \n", + " else:\n", + " print('Tie') \n", + " \n", + " return\n", + "\n", + "\n", + "## Rafa's solution:\n", + "## def round_results():\n", + "## p_choice = player_choice()\n", + "## print('\\nplayer choice is', p_choice)\n", + "\n", + "## cp_choice = cpu_choice()\n", + "## print('\\nplayer choice is', cpu_choice)\n", + "## winning_round = winner(cpu_choice, p_choice)\n", + "## \n", + "## print('the winner is', winning round)\n", + "## global n_rounds, player_score, cpu_score\n", + "## n_rounds = n_rounds + 1\n", + "## if winning_round == 1: cpu_score = cpu_score + 1\n", + "## if winning_round == 2: player_score = player_score + 1" + ] }, { "cell_type": "markdown", @@ -168,10 +275,64 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 13, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rock\n", + "choice of player: rock \n", + "choice of computer: paper\n", + "computer wins\n", + "\n", + "\n", + "paper\n", + "choice of player: paper \n", + "choice of computer: scissors\n", + "computer wins\n", + "\n", + "\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: rock\n", + "Tie\n", + "\n", + "\n", + "player score: 0 in 3 \n", + "computer score: 2 in 3\n" + ] + } + ], + "source": [ + "for i in range(0, n_rounds): \n", + " \n", + " cpu = ran_ges()\n", + " player = pl_ges()\n", + " \n", + " dis = decision(cpu, player)\n", + " if dis == 1:\n", + " cpu_score += 1\n", + " elif dis == 2:\n", + " player_score +=1\n", + " \n", + " announcement()\n", + " print('\\n') \n", + " \n", + "print('player score: ', player_score, ' in ', n_rounds, '\\ncomputer score: ', cpu_score, ' in ', n_rounds ) \n", + "\n", + "\n", + "# Rafa's solution:\n", + "#n_rounds = 0\n", + "#cpu_score, player_score = 0\n", + "#rounds_to_win = 3\n", + "\n", + "# while(cpu_score < rounds_to_win and player_score < rounds_to_win <7):\n", + "# round_results() " + ] }, { "cell_type": "markdown", @@ -183,10 +344,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computer is the final winner\n" + ] + } + ], + "source": [ + "if cpu_score > player_score:\n", + " print('Computer is the final winner')\n", + "\n", + "elif player_score > cpu_score:\n", + " print('Player is the final winner')\n", + "\n", + "else:\n", + " print('The game ended in a tie')" + ] }, { "cell_type": "markdown", @@ -202,6 +380,166 @@ "**Hint**: Try to reuse the code that you already coded in the previous challenge. If your code is efficient, this bonus will only consist of simple modifications to the original game." ] }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "please enter a number of rounds: 3\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: scissors\n", + "player wins\n", + "\n", + "\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: lizard\n", + "player wins\n", + "\n", + "\n", + "rock\n", + "choice of player: rock \n", + "choice of computer: rock\n", + "Tie\n", + "\n", + "\n", + "player score: 2 in \n", + "computer score: 0 in \n", + "Player is the final winner\n" + ] + } + ], + "source": [ + "import random\n", + "\n", + "gestures = ['rock', 'paper', 'scissors', 'lizard', 'spock']\n", + "\n", + "# definition of number of rounds\n", + "def n_rounds():\n", + " n = int(input('please enter a number of rounds: '))\n", + " if n%2 == 1:\n", + " return n\n", + " else:\n", + " print('enter an odd number: ')\n", + " n_rounds()\n", + " \n", + "\n", + "cpu_score = 0\n", + "player_score = 0\n", + "\n", + "\n", + "# Computer's choice:\n", + "def ran_ges():\n", + " return random.choice(gestures) \n", + "\n", + "\n", + "# Player's choice:\n", + "def pl_ges():\n", + " while(True):\n", + " a = input() \n", + " a in gestures; break \n", + " return a\n", + " \n", + " \n", + "# def player_choice():\n", + " while(True):\n", + " player_input = input() \n", + " player_input in gestures; break\n", + " return player_input \n", + "\n", + "\n", + "# Decision on the game results:\n", + "def decision(c, p):\n", + "\n", + " if c == p :\n", + " return 0 \n", + " elif c == 'paper':\n", + " if (p == 'rock') or (p == 'spock'):\n", + " return 1\n", + " else:\n", + " return 2\n", + " elif c == 'scissors':\n", + " if (p == 'paper') or (p == 'lizard'):\n", + " return 1\n", + " else:\n", + " return 2\n", + " elif c == 'lizard':\n", + " if (p == 'paper') or (p == 'spock'):\n", + " return 1\n", + " else:\n", + " return 2 \n", + " elif c == 'spock':\n", + " if (p == 'scissors') or (p == 'rock'):\n", + " return 1\n", + " else:\n", + " return 2 \n", + " else:\n", + " if (p == 'scissors') or (p == 'lizard'):\n", + " return 1\n", + " else:\n", + " return 2 \n", + " \n", + "\n", + "# announcement who is the winner\n", + "def announcement ():\n", + "\n", + " print('choice of player: ', player, '\\nchoice of computer: ', cpu)\n", + " \n", + " if dis == 1:\n", + " print('computer wins')\n", + " elif dis == 2:\n", + " print('player wins')\n", + " else:\n", + " print('Tie') \n", + " \n", + " return\n", + "\n", + "\n", + "# start to playing game\n", + "\n", + "l = int(n_rounds())\n", + "\n", + "for i in range(0,l): \n", + " \n", + " cpu = ran_ges()\n", + " player = pl_ges()\n", + " \n", + " dis = decision(cpu, player)\n", + " if dis == 1:\n", + " cpu_score += 1\n", + " elif dis == 2:\n", + " player_score +=1\n", + " \n", + " announcement()\n", + " print('\\n') \n", + " \n", + "print('player score: ', player_score, ' in ', n_rounds, '\\ncomputer score: ', cpu_score, ' in ', n_rounds ) \n", + "\n", + "\n", + "\n", + "# decising on final winner\n", + "if cpu_score > player_score:\n", + " print('Computer is the final winner')\n", + "\n", + "elif player_score > cpu_score:\n", + " print('Player is the final winner')\n", + "\n", + "else:\n", + " print('The game ended in a tie')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -226,7 +564,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/2.-Statistics/1-on set.png b/2.-Statistics/1-on set.png new file mode 100644 index 000000000..f94b9e50b Binary files /dev/null and b/2.-Statistics/1-on set.png differ diff --git a/2.-Statistics/10-0-tangent line to Function & exponent & logarithms.png b/2.-Statistics/10-0-tangent line to Function & exponent & logarithms.png new file mode 100644 index 000000000..ed72cc8d7 Binary files /dev/null and b/2.-Statistics/10-0-tangent line to Function & exponent & logarithms.png differ diff --git a/2.-Statistics/10-1-tangent line to Function & exponent & logarithms.png b/2.-Statistics/10-1-tangent line to Function & exponent & logarithms.png new file mode 100644 index 000000000..608f8894e Binary files /dev/null and b/2.-Statistics/10-1-tangent line to Function & exponent & logarithms.png differ diff --git a/2.-Statistics/10-2-tangent line to Function & exponent & logarithms.png b/2.-Statistics/10-2-tangent line to Function & exponent & logarithms.png new file mode 100644 index 000000000..a6b723208 Binary files /dev/null and b/2.-Statistics/10-2-tangent line to Function & exponent & logarithms.png differ diff --git a/2.-Statistics/11-0-probability concept.png b/2.-Statistics/11-0-probability concept.png new file mode 100644 index 000000000..67f0d4f62 Binary files /dev/null and b/2.-Statistics/11-0-probability concept.png differ diff --git a/2.-Statistics/11-1-probability concept.png b/2.-Statistics/11-1-probability concept.png new file mode 100644 index 000000000..a135479aa Binary files /dev/null and b/2.-Statistics/11-1-probability concept.png differ diff --git a/2.-Statistics/12-0-problem solving.png b/2.-Statistics/12-0-problem solving.png new file mode 100644 index 000000000..a95bcc0a2 Binary files /dev/null and b/2.-Statistics/12-0-problem solving.png differ diff --git a/2.-Statistics/12-1-problem solving.png b/2.-Statistics/12-1-problem solving.png new file mode 100644 index 000000000..85aed6895 Binary files /dev/null and b/2.-Statistics/12-1-problem solving.png differ diff --git a/2.-Statistics/12-2-problem solving.png b/2.-Statistics/12-2-problem solving.png new file mode 100644 index 000000000..f5ddfaca6 Binary files /dev/null and b/2.-Statistics/12-2-problem solving.png differ diff --git a/2.-Statistics/13-0-Bayes Theorem and binomial.png b/2.-Statistics/13-0-Bayes Theorem and binomial.png new file mode 100644 index 000000000..f29cf1163 Binary files /dev/null and b/2.-Statistics/13-0-Bayes Theorem and binomial.png differ diff --git a/2.-Statistics/13-1-Bayes Theorem and binomial.png b/2.-Statistics/13-1-Bayes Theorem and binomial.png new file mode 100644 index 000000000..3954591fc Binary files /dev/null and b/2.-Statistics/13-1-Bayes Theorem and binomial.png differ diff --git a/2.-Statistics/13-2-Bayes Theorem and binomial.png b/2.-Statistics/13-2-Bayes Theorem and binomial.png new file mode 100644 index 000000000..4b400ecc5 Binary files /dev/null and b/2.-Statistics/13-2-Bayes Theorem and binomial.png differ diff --git a/2.-Statistics/13-3-Bayes Theorem and binomial.png b/2.-Statistics/13-3-Bayes Theorem and binomial.png new file mode 100644 index 000000000..6ebce099b Binary files /dev/null and b/2.-Statistics/13-3-Bayes Theorem and binomial.png differ diff --git a/2.-Statistics/13-4-Bayes Theorem and binomial.png b/2.-Statistics/13-4-Bayes Theorem and binomial.png new file mode 100644 index 000000000..80ae20d94 Binary files /dev/null and b/2.-Statistics/13-4-Bayes Theorem and binomial.png differ diff --git a/2.-Statistics/14-0-probablity(basic and intermediate).png b/2.-Statistics/14-0-probablity(basic and intermediate).png new file mode 100644 index 000000000..3a4a2793d Binary files /dev/null and b/2.-Statistics/14-0-probablity(basic and intermediate).png differ diff --git a/2.-Statistics/14-1-probablity(basic and intermediate).png b/2.-Statistics/14-1-probablity(basic and intermediate).png new file mode 100644 index 000000000..57aabc1a2 Binary files /dev/null and b/2.-Statistics/14-1-probablity(basic and intermediate).png differ diff --git a/2.-Statistics/2-on the Number Line, including Inequalities.png b/2.-Statistics/2-on the Number Line, including Inequalities.png new file mode 100644 index 000000000..760ee47bd Binary files /dev/null and b/2.-Statistics/2-on the Number Line, including Inequalities.png differ diff --git a/2.-Statistics/3-0-Simplication Rules and Sigma Notation.png b/2.-Statistics/3-0-Simplication Rules and Sigma Notation.png new file mode 100644 index 000000000..ca4f69e44 Binary files /dev/null and b/2.-Statistics/3-0-Simplication Rules and Sigma Notation.png differ diff --git a/2.-Statistics/3-1-Simplication Rules and Sigma Notation.png b/2.-Statistics/3-1-Simplication Rules and Sigma Notation.png new file mode 100644 index 000000000..90f7f893b Binary files /dev/null and b/2.-Statistics/3-1-Simplication Rules and Sigma Notation.png differ diff --git a/2.-Statistics/4-0-on sets-number line-inequalities-simplification and sigma notation.png b/2.-Statistics/4-0-on sets-number line-inequalities-simplification and sigma notation.png new file mode 100644 index 000000000..cd7e3a995 Binary files /dev/null and b/2.-Statistics/4-0-on sets-number line-inequalities-simplification and sigma notation.png differ diff --git a/2.-Statistics/4-1-on sets-number line-inequalities-simplification and sigma notation.png b/2.-Statistics/4-1-on sets-number line-inequalities-simplification and sigma notation.png new file mode 100644 index 000000000..eed3f7678 Binary files /dev/null and b/2.-Statistics/4-1-on sets-number line-inequalities-simplification and sigma notation.png differ diff --git a/2.-Statistics/4-2-on sets-number line-inequalities-simplification and sigma notation.png b/2.-Statistics/4-2-on sets-number line-inequalities-simplification and sigma notation.png new file mode 100644 index 000000000..5186928e9 Binary files /dev/null and b/2.-Statistics/4-2-on sets-number line-inequalities-simplification and sigma notation.png differ diff --git a/2.-Statistics/4-3-on sets-number line-inequalities-simplification and sigma notation.png b/2.-Statistics/4-3-on sets-number line-inequalities-simplification and sigma notation.png new file mode 100644 index 000000000..b5ab67488 Binary files /dev/null and b/2.-Statistics/4-3-on sets-number line-inequalities-simplification and sigma notation.png differ diff --git a/2.-Statistics/4-4-on sets-number line-inequalities-simplification and sigma notation.png b/2.-Statistics/4-4-on sets-number line-inequalities-simplification and sigma notation.png new file mode 100644 index 000000000..70ae82577 Binary files /dev/null and b/2.-Statistics/4-4-on sets-number line-inequalities-simplification and sigma notation.png differ diff --git a/2.-Statistics/5-Cartesian Plane.png b/2.-Statistics/5-Cartesian Plane.png new file mode 100644 index 000000000..61c9d9429 Binary files /dev/null and b/2.-Statistics/5-Cartesian Plane.png differ diff --git a/2.-Statistics/6-0-Types of Functions.png b/2.-Statistics/6-0-Types of Functions.png new file mode 100644 index 000000000..187185c30 Binary files /dev/null and b/2.-Statistics/6-0-Types of Functions.png differ diff --git a/2.-Statistics/6-1-Types of Functions.png b/2.-Statistics/6-1-Types of Functions.png new file mode 100644 index 000000000..c49efd74d Binary files /dev/null and b/2.-Statistics/6-1-Types of Functions.png differ diff --git a/2.-Statistics/7-0-Cartesian Plane & Types of Functions.png b/2.-Statistics/7-0-Cartesian Plane & Types of Functions.png new file mode 100644 index 000000000..3930c385e Binary files /dev/null and b/2.-Statistics/7-0-Cartesian Plane & Types of Functions.png differ diff --git a/2.-Statistics/7-1-Cartesian Plane & Types of Functions.png b/2.-Statistics/7-1-Cartesian Plane & Types of Functions.png new file mode 100644 index 000000000..0a0d19994 Binary files /dev/null and b/2.-Statistics/7-1-Cartesian Plane & Types of Functions.png differ diff --git a/2.-Statistics/7-2-Cartesian Plane & Types of Functions.png b/2.-Statistics/7-2-Cartesian Plane & Types of Functions.png new file mode 100644 index 000000000..401000ff9 Binary files /dev/null and b/2.-Statistics/7-2-Cartesian Plane & Types of Functions.png differ diff --git a/2.-Statistics/8-Tangent lines to functions.png b/2.-Statistics/8-Tangent lines to functions.png new file mode 100644 index 000000000..2cce1a252 Binary files /dev/null and b/2.-Statistics/8-Tangent lines to functions.png differ diff --git a/2.-Statistics/9-0-Exponent and logarithm.png b/2.-Statistics/9-0-Exponent and logarithm.png new file mode 100644 index 000000000..be421399c Binary files /dev/null and b/2.-Statistics/9-0-Exponent and logarithm.png differ diff --git a/2.-Statistics/9-1-Exponent and logarithm.png b/2.-Statistics/9-1-Exponent and logarithm.png new file mode 100644 index 000000000..b82ecd309 Binary files /dev/null and b/2.-Statistics/9-1-Exponent and logarithm.png differ diff --git a/2.-Statistics/9-2-Exponent and logarithm.png b/2.-Statistics/9-2-Exponent and logarithm.png new file mode 100644 index 000000000..87cb98934 Binary files /dev/null and b/2.-Statistics/9-2-Exponent and logarithm.png differ diff --git a/robot-2.md b/robot-2.md new file mode 100644 index 000000000..e69de29bb diff --git a/robot.md b/robot.md new file mode 100644 index 000000000..e69de29bb