diff --git a/1.-Python/1.-Snail-and-Well/1.-Snail-and-Well/snail-and-well.ipynb b/1.-Python/1.-Snail-and-Well/1.-Snail-and-Well/snail-and-well.ipynb new file mode 100644 index 000000000..d1f468679 --- /dev/null +++ b/1.-Python/1.-Snail-and-Well/1.-Snail-and-Well/snail-and-well.ipynb @@ -0,0 +1,276 @@ +{ + "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": 13, + "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": 7, + "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": 24, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "while well_height > snail_position:\n", + " snail_position = snail_position + daily_distance \n", + " days += 1\n", + " if well_height > snail_position:\n", + " snail_position = snail_position + nightly_distance\n", + " else:\n", + " solution = str(days)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Print the solution." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The snail takes 11\n" + ] + } + ], + "source": [ + "print(\"The snail takes\", days)" + ] + }, + { + "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": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The snail takes5\n" + ] + } + ], + "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", + "days = 0\n", + "while well_height > snail_position:\n", + " snail_position = snail_position + advance_cm[days]\n", + " days += 1\n", + " if well_height > snail_position:\n", + " snail_position = snail_position + nightly_distance\n", + " else:\n", + " print(\"The snail takes\" + str(days))" + ] + }, + { + "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": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The maximum displacement in a day is 85 cm.\n", + "The minimum displacement in a day is -8 cm.\n" + ] + } + ], + "source": [ + "displacement = []\n", + "counter = 0\n", + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "days = 11\n", + "daily_distance = 30\n", + "nightly_distance = -20\n", + "for i in advance_cm[:days]:\n", + " if counter < (days - 1):\n", + " displacement.append(i + nightly_distance)\n", + " else:\n", + " displacement.append(i + daily_distance)\n", + " counter += 1\n", + "print(\"The maximum displacement in a day is\", max(displacement), \"cm.\")\n", + "print(\"The minimum displacement in a day is\", min(displacement), \"cm.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. What is its average progress? Take into account the snail slides at night." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average progress of the mighty snail is 22.636363636363637 cm in a day.\n" + ] + } + ], + "source": [ + "print(\"The average progress of the mighty snail is\", sum(displacement)/len(displacement), \"cm in a day.\")" + ] + }, + { + "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": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation of the snailing walkation is 26.84\n" + ] + } + ], + "source": [ + "mean = sum(displacement)/len(displacement)\n", + "sumsquare = 0\n", + "lesquare = 0\n", + "for i in displacement:\n", + " lesquare = (i - mean)**2\n", + " sumsquare = sumsquare + lesquare\n", + "irregular = (sumsquare/(days - 1))**.5\n", + "\n", + "print(\"The standard deviation of the snailing walkation is\",round(irregular, 2))" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/1.-Snail-and-Well/snail-and-well-checkpoint.ipynb b/1.-Python/1.-Snail-and-Well/snail-and-well-checkpoint.ipynb new file mode 100644 index 000000000..d1f468679 --- /dev/null +++ b/1.-Python/1.-Snail-and-Well/snail-and-well-checkpoint.ipynb @@ -0,0 +1,276 @@ +{ + "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": 13, + "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": 7, + "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": 24, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "while well_height > snail_position:\n", + " snail_position = snail_position + daily_distance \n", + " days += 1\n", + " if well_height > snail_position:\n", + " snail_position = snail_position + nightly_distance\n", + " else:\n", + " solution = str(days)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Print the solution." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The snail takes 11\n" + ] + } + ], + "source": [ + "print(\"The snail takes\", days)" + ] + }, + { + "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": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The snail takes5\n" + ] + } + ], + "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", + "days = 0\n", + "while well_height > snail_position:\n", + " snail_position = snail_position + advance_cm[days]\n", + " days += 1\n", + " if well_height > snail_position:\n", + " snail_position = snail_position + nightly_distance\n", + " else:\n", + " print(\"The snail takes\" + str(days))" + ] + }, + { + "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": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The maximum displacement in a day is 85 cm.\n", + "The minimum displacement in a day is -8 cm.\n" + ] + } + ], + "source": [ + "displacement = []\n", + "counter = 0\n", + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "days = 11\n", + "daily_distance = 30\n", + "nightly_distance = -20\n", + "for i in advance_cm[:days]:\n", + " if counter < (days - 1):\n", + " displacement.append(i + nightly_distance)\n", + " else:\n", + " displacement.append(i + daily_distance)\n", + " counter += 1\n", + "print(\"The maximum displacement in a day is\", max(displacement), \"cm.\")\n", + "print(\"The minimum displacement in a day is\", min(displacement), \"cm.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. What is its average progress? Take into account the snail slides at night." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average progress of the mighty snail is 22.636363636363637 cm in a day.\n" + ] + } + ], + "source": [ + "print(\"The average progress of the mighty snail is\", sum(displacement)/len(displacement), \"cm in a day.\")" + ] + }, + { + "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": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation of the snailing walkation is 26.84\n" + ] + } + ], + "source": [ + "mean = sum(displacement)/len(displacement)\n", + "sumsquare = 0\n", + "lesquare = 0\n", + "for i in displacement:\n", + " lesquare = (i - mean)**2\n", + " sumsquare = sumsquare + lesquare\n", + "irregular = (sumsquare/(days - 1))**.5\n", + "\n", + "print(\"The standard deviation of the snailing walkation is\",round(irregular, 2))" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/2.-Duel-of-Sorcerers/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb b/1.-Python/2.-Duel-of-Sorcerers/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb new file mode 100644 index 000000000..e8e2c0be5 --- /dev/null +++ b/1.-Python/2.-Duel-of-Sorcerers/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb @@ -0,0 +1,382 @@ +{ + "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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf = [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(gandalf)\n", + "spells = len(saruman)" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0 " + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(spells):\n", + " if gandalf[i] > saruman[i]:\n", + " gandalf_wins += 1\n", + " elif gandalf[i] < saruman[i]:\n", + " saruman_wins += 1" + ] + }, + { + "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": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tie\n" + ] + } + ], + "source": [ + "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", + "spells = len(gandalf)\n", + "spells = len(saruman)\n", + "\n", + "gandalf_wins = 0\n", + "saruman_wins = 0 \n", + "\n", + "if gandalf_wins > saruman_wins:\n", + " print(\"Gandalf wins\")\n", + "elif gandalf_wins < saruman_wins:\n", + " print(\"Saruman wins\")\n", + "else:\n", + " print(\"Tie\",)" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "power = {\n", + " 'Fireball': 50, \n", + " 'Lightning bolt': 40, \n", + " 'Magic arrow': 10, \n", + " 'Black Tentacles': 25, \n", + " 'Contagion': 45\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", + "spells = 0" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0" + ] + }, + { + "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": 1, + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "gandalf_power = []\n", + "for i in gandalf:\n", + " gandalf_power.append(POWER[i])\n", + " \n", + "saruman_power = []\n", + "for i in saruman:\n", + " saruman_power.append(POWER[i])" + ] + }, + { + "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": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf wins\n" + ] + } + ], + "source": [ + "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", + "power = {'Fireball': 50, \n", + " 'Lightning bolt': 40, \n", + " 'Magic arrow': 10, \n", + " 'Black Tentacles': 25, \n", + " 'Contagion': 45\n", + "}\n", + "\n", + "spells = 0\n", + "gandalf_wins = 0\n", + "saruman_wins = 0\n", + "\n", + "gandalf_power = []\n", + "for i in gandalf:\n", + " gandalf_power.append(power[i])\n", + " \n", + "saruman_power = []\n", + "for i in saruman:\n", + " saruman_power.append(power[i])\n", + " \n", + "while gandalf_wins != 3 and saruman_wins != 3: \n", + " if gandalf_power[spells] > saruman_power[spells]:\n", + " gandalf_wins += 1\n", + " while gandalf_wins in [1,2]:\n", + " spells += 1\n", + " if gandalf_power[spells] > saruman_power[spells]:\n", + " gandalf_wins += 1\n", + " else:\n", + " gandalf_wins = 0\n", + " elif gandalf_power[spells] < saruman_power[spells]:\n", + " saruman_wins += 1\n", + " while saruman_wins in [1,2]:\n", + " spells += 1\n", + " if gandalf_power[spells] < saruman_power[spells]:\n", + " saruman_wins += 1\n", + " else:\n", + " saruman_wins = 0 \n", + "\n", + "if gandalf_wins > saruman_wins:\n", + " print(\"Gandalf wins\")\n", + "else:\n", + " print(\"Saruman wins\") " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5. Find the average spell power of Gandalf and Saruman. " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf's mean is:39\n", + "Saruman's mean is:30.5\n" + ] + } + ], + "source": [ + "from statistics import mean\n", + "print(f\"Gandalf's mean is:{round(mean(gandalf_power), 2)}\")\n", + "from statistics import mean\n", + "print(f\"Saruman's mean is:{round(mean(saruman_power), 2)}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 6. Find the standard deviation of the spell power of Gandalf and Saruman. " + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf's Standard deviation powers is: 15.95\n", + "saruman's Standard deviation powers is: 16.41\n" + ] + } + ], + "source": [ + "from statistics import stdev\n", + "print(f\"Gandalf's Standard deviation powers is: {round(stdev(gandalf_power), 2)}\")\n", + "from statistics import stdev\n", + "print(f\"saruman's Standard deviation powers is: {round(stdev(saruman_power), 2)}\")" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/2.-Duel-of-Sorcerers/2.-Duel-of-Sorcerers/images/content_lightning_bolt_big.jpg b/1.-Python/2.-Duel-of-Sorcerers/2.-Duel-of-Sorcerers/images/content_lightning_bolt_big.jpg new file mode 100644 index 000000000..dbca3ddb0 Binary files /dev/null and b/1.-Python/2.-Duel-of-Sorcerers/2.-Duel-of-Sorcerers/images/content_lightning_bolt_big.jpg differ diff --git a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers-checkpoint.ipynb b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers-checkpoint.ipynb new file mode 100644 index 000000000..7078b95e1 --- /dev/null +++ b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers-checkpoint.ipynb @@ -0,0 +1,339 @@ +{ + "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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf = [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(gandalf)\n", + "spells = len(saruman)" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0 " + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(spells):\n", + " if gandalf[i] > saruman[i]:\n", + " gandalf_wins += 1\n", + " elif gandalf[i] < saruman[i]:\n", + " saruman_wins += 1" + ] + }, + { + "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": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tie\n" + ] + } + ], + "source": [ + "gandalf = [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(gandalf)\n", + "spells = len(saruman)\n", + "gandalf_wins = 0\n", + "saruman_wins = 0 \n", + "if gandalf_wins > saruman_wins:\n", + " print(\"Gandalf wins\")\n", + "elif gandalf_wins < saruman_wins:\n", + " print(\"Saruman wins\")\n", + "else:\n", + " print(\"Tie\",)" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "power = {'Fireball': 50, 'Lightning bolt': 40, 'Magic arrow': 10, 'Black Tentacles': 25, 'Contagion': 45}\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", + "spells = 10" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0" + ] + }, + { + "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": 42, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "ename": "KeyError", + "evalue": "10", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mgandalf_power\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mgandalf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mgandalf_power\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpower\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpower\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0msaruman_power\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mKeyError\u001b[0m: 10" + ] + } + ], + "source": [ + "gandalf_power = []\n", + "saruman_power = []\n", + "for spell_name in gandalf:\n", + " gandalf_power = gandalf_power + [power[spell_name]]\n", + "for spell_name in saruman:\n", + " saruman_power = saruman_power + [power[spell_name]]" + ] + }, + { + "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": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf will cast 0 spells\n", + "Saruman will cast 0 spells\n", + "********** BATTLE START **********\n" + ] + } + ], + "source": [ + "while gandalf_wins != 3 and saruman_wins != 3: \n", + " if gandalf_power[spells] > saruman_power[spells]:\n", + " gandalf_wins += 1\n", + " print(\"gandalf wins\")\n", + "while gandalf_wins in [1,2]:\n", + " spells += 1\n", + " if gandalf_power[spells] > saruman_power[spells]:\n", + " gandalf_wins += 1\n", + " else:\n", + " gandalf_wins = 0\n", + " elif gandalf_power[spells] < saruman_power[spells]:\n", + " saruman_wins += 1\n", + " while saruman_wins in [1,2]:\n", + " spells += 1\n", + " if gandalf_power[spells] < saruman_power[spells]:\n", + " saruman_wins += 1\n", + " else:\n", + " saruman_wins = 0 " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5. Find the average spell power of Gandalf and Saruman. " + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'g_spell_power' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mstatistics\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmean\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"average gandalf\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mg_spell_power\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mNameError\u001b[0m: name 'g_spell_power' is not defined" + ] + } + ], + "source": [ + "from statistics import mean\n", + "print(\"average gandalf\", g_spell_power)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 6. Find the standard deviation of the spell power of Gandalf and Saruman. " + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/3.-Bus/3.-Bus/bus.ipynb b/1.-Python/3.-Bus/3.-Bus/bus.ipynb new file mode 100644 index 000000000..284fcf6bf --- /dev/null +++ b/1.-Python/3.-Bus/3.-Bus/bus.ipynb @@ -0,0 +1,296 @@ +{ + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "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": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 56, + "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": 50, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "new_list = []\n", + "total = 0\n", + "\n", + "for i in stops:\n", + " num_passenger = (i[0]) - (i[1])\n", + " \n", + " total += num_passenger\n", + " \n", + " new_list.append(total)\n", + " \n", + "print(new_list)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 3, -2, -1, 4, -4, -3, -2, -1]\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "new_list = []\n", + "\n", + "for a, b in stops:\n", + " \n", + " num_passenger = a - b\n", + " \n", + " new_list.append(num_passenger)\n", + "\n", + "print(new_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "passenger_per_stop = []\n", + "\n", + "total = 0\n", + "\n", + "for i in new_list: \n", + " total += i\n", + " passenger_per_stop.append(total)\n", + " \n", + "print(passenger_per_stop)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the maximum occupation of the bus." + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(passenger_per_stop)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Calculate the average occupation. And the standard deviation." + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9.333333333333334" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(passenger_per_stop)/len(stops)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 3, -2, -1, 4, -4, -3, -2, -1]\n", + "[10, 13, 11, 10, 14, 10, 7, 5, 4]\n", + "The standard deviation is 3.39\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "new_list = []\n", + "\n", + "for a, b in stops:\n", + " \n", + " num_passenger = a - b\n", + " \n", + " new_list.append(num_passenger)\n", + "\n", + "print(new_list)\n", + "\n", + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "passenger_per_stop = []\n", + "\n", + "total = 0\n", + "\n", + "for i in new_list: \n", + " total += i\n", + " passenger_per_stop.append(total)\n", + " \n", + "print(passenger_per_stop)\n", + "\n", + "import statistics\n", + "from statistics import stdev\n", + "print(\"The standard deviation is\", round(statistics.stdev(passenger_per_stop), 2))" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/3.-Bus/bus-checkpoint.ipynb b/1.-Python/3.-Bus/bus-checkpoint.ipynb new file mode 100644 index 000000000..e0d0b684c --- /dev/null +++ b/1.-Python/3.-Bus/bus-checkpoint.ipynb @@ -0,0 +1,269 @@ +{ + "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": null, + "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": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 56, + "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": 50, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "new_list = []\n", + "total = 0\n", + "\n", + "for i in stops:\n", + " num_passenger = (i[0]) - (i[1])\n", + " \n", + " total += num_passenger\n", + " \n", + " new_list.append(total)\n", + " \n", + "print(new_list)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 3, -2, -1, 4, -4, -3, -2, -1]\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "new_list = []\n", + "\n", + "for a, b in stops:\n", + " \n", + " num_passenger = a - b\n", + " \n", + " new_list.append(num_passenger)\n", + "\n", + "print(new_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n", + "\n", + "passenger_per_stop = []\n", + "\n", + "total = 0\n", + "\n", + "for i in new_list: \n", + " total += i\n", + " passenger_per_stop.append(total)\n", + " \n", + "print(passenger_per_stop)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the maximum occupation of the bus." + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(passenger_per_stop)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Calculate the average occupation. And the standard deviation." + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9.333333333333334" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(passenger_per_stop)/len(stops)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'stdev' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mstdev\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpassenger_per_stop\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mNameError\u001b[0m: name 'stdev' is not defined" + ] + } + ], + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/4.-Robin-Hood/4.-Robin-Hood/images/arrows.jpg b/1.-Python/4.-Robin-Hood/4.-Robin-Hood/images/arrows.jpg new file mode 100644 index 000000000..88f1ba640 Binary files /dev/null and b/1.-Python/4.-Robin-Hood/4.-Robin-Hood/images/arrows.jpg differ diff --git a/1.-Python/4.-Robin-Hood/4.-Robin-Hood/robin-hood.ipynb b/1.-Python/4.-Robin-Hood/4.-Robin-Hood/robin-hood.ipynb new file mode 100644 index 000000000..ed193cd88 --- /dev/null +++ b/1.-Python/4.-Robin-Hood/4.-Robin-Hood/robin-hood.ipynb @@ -0,0 +1,238 @@ +{ + "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": null, + "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": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{(-3, 2), (4, 5), (5, 7), (2, 2)}\n" + ] + } + ], + "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)]\n", + "\n", + "arrow_hitsarrow = []\n", + "\n", + "for i in range(len(points)):\n", + " if points[i] in points[i+1:]:\n", + " arrow_hitsarrow.append(points[i])\n", + "print(set(arrow_hitsarrow))" + ] + }, + { + "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": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total10 quadran1 6 quadrant 2, 2 qudrant 32 arrows in quadrant 4.\n", + "0\n" + ] + } + ], + "source": [ + "q1 = []\n", + "q2 = []\n", + "q3 = []\n", + "q4 = []\n", + "\n", + "count = 0\n", + "\n", + "while count < len(points):\n", + " for one,two in points[count:count+1]:\n", + " if one > 0 and two > 0:\n", + " q1.append(points[count])\n", + " elif one > 0 and two < 0:\n", + " q4.append(points[count])\n", + " elif one < 0 and two > 0:\n", + " q2.append(points[count])\n", + " elif one < 0 and two < 0:\n", + " q3.append(points[count])\n", + " \n", + " count += 1\n", + "solution = \"total\" + str(len(q1)) + \" quadran1 \" + str(len(q2)) + \" quadrant 2, \" + str(len(q3)) + \" qudrant 3\" + str(len(q4)) + \" arrows in quadrant 4.\"\n", + "print(solution)\n", + "print(points[7:].index((5,7)))" + ] + }, + { + "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": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6.4, 2.0, 8.06, 3.16, 3.61, 6.4, 3.61, 8.6, 8.6, 2.83, 6.4, 2.0, 8.06, 3.16, 3.61, 6.4, 3.61, 8.6, 8.6, 2.83, 12.73, 12.04]\n", + "The closest point [(0, 2), (0, -2)]\n", + "The distance of the closest point 2.0\n" + ] + } + ], + "source": [ + "import math\n", + "def kurz(shot):\n", + " one = shot[0]\n", + " two = shot[1]\n", + " distance = math.sqrt(one**2 + two**2)\n", + " return distance\n", + "\n", + "\n", + "distances = []\n", + "\n", + "for i in points:\n", + " distances.append(round(kurz(i), 2))\n", + "print(distances)\n", + "\n", + "\n", + "counter = 0\n", + "\n", + "mark = []\n", + "\n", + "for i in distances:\n", + " if i == min(distances):\n", + " mark.append(points[counter])\n", + " counter += 1 \n", + "\n", + "print(\"The closest point\", mark)\n", + "print(\"The distance of the closest point\", min(distances))" + ] + }, + { + "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": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 not hit\n" + ] + } + ], + "source": [ + "radius = 9\n", + "print(sum(1 for i in distances if i > radius), \"not hit\")" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/4.-Robin-Hood/robin-hood-checkpoint.ipynb b/1.-Python/4.-Robin-Hood/robin-hood-checkpoint.ipynb new file mode 100644 index 000000000..67128efa2 --- /dev/null +++ b/1.-Python/4.-Robin-Hood/robin-hood-checkpoint.ipynb @@ -0,0 +1,240 @@ +{ + "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": null, + "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": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{(-3, 2), (4, 5), (5, 7), (2, 2)}\n" + ] + } + ], + "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)]\n", + "\n", + "arrow_hitsarrow = []\n", + "\n", + "for i in range(len(points)):\n", + " if points[i] in points[i+1:]:\n", + " arrow_hitsarrow.append(points[i])\n", + "print(set(arrow_hitsarrow))" + ] + }, + { + "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": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total10 quadran1 6 quadrant 2, 2 qudrant 32 arrows in quadrant 4.\n", + "0\n" + ] + } + ], + "source": [ + "q1 = []\n", + "q2 = []\n", + "q3 = []\n", + "q4 = []\n", + "\n", + "count = 0\n", + "\n", + "while count < len(points):\n", + " for one,two in points[count:count+1]:\n", + " if one > 0 and two > 0:\n", + " q1.append(points[count])\n", + " elif one > 0 and two < 0:\n", + " q4.append(points[count])\n", + " elif one < 0 and two > 0:\n", + " q2.append(points[count])\n", + " elif one < 0 and two < 0:\n", + " q3.append(points[count])\n", + " \n", + " count += 1\n", + "solution = \"total\" + str(len(q1)) + \" quadran1 \" + str(len(q2)) + \" quadrant 2, \" + str(len(q3)) + \" qudrant 3\" + str(len(q4)) + \" arrows in quadrant 4.\"\n", + "print(solution)\n", + "print(points[7:].index((5,7)))" + ] + }, + { + "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": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6.4, 2.0, 8.06, 3.16, 3.61, 6.4, 3.61, 8.6, 8.6, 2.83, 6.4, 2.0, 8.06, 3.16, 3.61, 6.4, 3.61, 8.6, 8.6, 2.83, 12.73, 12.04]\n", + "The closest point [(0, 2), (0, -2)]\n", + "The distance of the closest point 2.0\n" + ] + } + ], + "source": [ + "import math\n", + "def kurz(shot):\n", + " one = shot[0]\n", + " two = shot[1]\n", + " distance = math.sqrt(one**2 + two**2)\n", + " return distance\n", + "\n", + "##creating list of distances\n", + "\n", + "distances = []\n", + "\n", + "for i in points:\n", + " distances.append(round(kurz(i), 2))\n", + "print(distances)\n", + "\n", + "##creating list of closest points\n", + "\n", + "counter = 0\n", + "\n", + "mark = []\n", + "\n", + "for i in distances:\n", + " if i == min(distances):\n", + " mark.append(points[counter])\n", + " counter += 1 \n", + "\n", + "print(\"The closest point\", mark)\n", + "print(\"The distance of the closest point\", min(distances))" + ] + }, + { + "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": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 not hit\n" + ] + } + ], + "source": [ + "radius = 9\n", + "print(sum(1 for i in distances if i > radius), \"not hit\")" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/5.-Temperature-Processor/5.-Temperature-Processor/temperature.ipynb b/1.-Python/5.-Temperature-Processor/5.-Temperature-Processor/temperature.ipynb new file mode 100644 index 000000000..67aed27db --- /dev/null +++ b/1.-Python/5.-Temperature-Processor/5.-Temperature-Processor/temperature.ipynb @@ -0,0 +1,452 @@ +{ + "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": null, + "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]" + ] + }, + { + "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": [ + "minimun temperature 0\n" + ] + } + ], + "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", + "minimum = min(temperatures_C)\n", + "\n", + "print(\"minimum temperature\", minimum)" + ] + }, + { + "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": [ + "maximum temperature 90\n" + ] + } + ], + "source": [ + "maximum = max(temperatures_C)\n", + "\n", + "print(\"maximum temperature\", maximum)" + ] + }, + { + "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": 30, + "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", + "hot_ones = [t for t in temperatures_C if t >= 70]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Find the average temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "from statistics import mean\n", + "average = round(mean(temperatures_C), 2)" + ] + }, + { + "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": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[33, 66, 65, 62.0, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n" + ] + } + ], + "source": [ + "temperatures_C[3] = (temperatures_C[2] + temperatures_C[4])/2\n", + "print(temperatures_C)" + ] + }, + { + "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$" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[91, 151, 149, 32, 138, 140, 144, 147, 158, 169, 176, 178, 176, 181, 194, 174, 142, 127, 122, 120, 127, 118, 113, 102]\n" + ] + } + ], + "source": [ + "temperatures_F = [round(x*1.8 + 32) for x in temperatures_C]\n", + "print(temperatures_F)" + ] + }, + { + "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": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "overheating\n" + ] + } + ], + "source": [ + "if len(hot_ones) >= 4 or m >= 80 in temperatures_C or average >= 65:\n", + " print(\"overheating\")\n", + "else:\n", + " print(\"cool.\")" + ] + }, + { + "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": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['9 A.M.', '10 A.M.', '11 A.M.', '12 P.M.', '1 P.M.', '2 P.M.', '3 P.M.']\n" + ] + } + ], + "source": [ + "more_than70 = []\n", + "for i in range(len(temperatures_C)):\n", + " if temperatures_C[i] > 70:\n", + " if i == 0:\n", + " more_than70.append('12 A.M.')\n", + " elif i > 12:\n", + " more_than70.append(str(i - 12) + ' P.M.')\n", + " elif i == 12:\n", + " more_than70.append(str(i) + ' P.M.')\n", + " else:\n", + " more_than70.append(str(i) + ' A.M.')\n", + "print(more_than70)" + ] + }, + { + "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": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There were {7} hours with temperatures above 70 C\n" + ] + } + ], + "source": [ + "print(\"There were\", {len(more_than70)}, \"hours with temperatures above 70 C\")" + ] + }, + { + "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": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "change the cooling system.\n" + ] + } + ], + "source": [ + "consexecution = 0\n", + "counter = 0\n", + "\n", + "while consexecution < 4 and len(temperatures_C) != (counter + 1):\n", + " if temperatures_C[counter] >= 70:\n", + " consexecution += 1\n", + " else:\n", + " consexecution = 0\n", + " counter += 1\n", + "\n", + " \n", + "if consexecution >= 4 or m >= 80 in temperatures_C or average >= 65:\n", + " print(\"change the cooling system.\")\n", + "else:\n", + " print(\"Cooling system effectiv.\")" + ] + }, + { + "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": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['9 A.M.', '10 A.M.', '11 A.M.', '12 P.M.', '1 P.M.', '2 P.M.', '3 P.M.']\n", + "change the cooling system.\n", + "The mean temperature in C is: 60.25\n", + "The mean temperature in F is: 140.38\n" + ] + } + ], + "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", + "temperatures_F = [round(x*1.8 + 32) for x in temperatures_C]\n", + "\n", + "more_than70 = []\n", + "for i in range(len(temperatures_C)):\n", + " if temperatures_C[i] > 70:\n", + " if i == 0:\n", + " more_than70.append('12 A.M.')\n", + " elif i > 12:\n", + " more_than70.append(str(i - 12) + ' P.M.')\n", + " elif i == 12:\n", + " more_than70.append(str(i) + ' P.M.')\n", + " else:\n", + " more_than70.append(str(i) + ' A.M.')\n", + "print(more_than70)\n", + "\n", + "consexecution = 0\n", + "counter = 0\n", + "\n", + "while consexecution < 4 and len(temperatures_C) != (counter + 1):\n", + " if temperatures_C[counter] >= 70:\n", + " consexecution += 1\n", + " else:\n", + " consexecution = 0\n", + " counter += 1\n", + "\n", + " \n", + "if consexecution >= 4 or m >= 80 in temperatures_C or average >= 65:\n", + " print(\"change the cooling system.\")\n", + "else:\n", + " print(\"Cooling system effectiv.\")\n", + " \n", + "from statistics import mean\n", + "print(f\"The mean temperature in C is: {round(mean(temperatures_C), 2)}\")\n", + "print(f\"The mean temperature in F is: {round(mean(temperatures_F), 2)}\")" + ] + }, + { + "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": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation from C is: 19.7\n", + "The standard deviation from F is: 35.51\n" + ] + } + ], + "source": [ + "from statistics import stdev\n", + "print(f\"The standard deviation from C is: {round(stdev(temperatures_C), 2)}\")\n", + "print(f\"The standard deviation from F is: {round(stdev(temperatures_F), 2)}\")" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python/5.-Temperature-Processor/temperature-checkpoint.ipynb b/1.-Python/5.-Temperature-Processor/temperature-checkpoint.ipynb new file mode 100644 index 000000000..abd0f0897 --- /dev/null +++ b/1.-Python/5.-Temperature-Processor/temperature-checkpoint.ipynb @@ -0,0 +1,394 @@ +{ + "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": null, + "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]" + ] + }, + { + "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": [ + "minimun temperature 0\n" + ] + } + ], + "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", + "minimum = min(temperatures_C)\n", + "\n", + "print(\"minimum temperature\", minimum)" + ] + }, + { + "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": [ + "maximum temperature 90\n" + ] + } + ], + "source": [ + "maximum = max(temperatures_C)\n", + "\n", + "print(\"maximum temperature\", maximum)" + ] + }, + { + "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": 30, + "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", + "hot_ones = [t for t in temperatures_C if t >= 70]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Find the average temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "from statistics import mean\n", + "average = round(mean(temperatures_C), 2)" + ] + }, + { + "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": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[33, 66, 65, 62.0, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n" + ] + } + ], + "source": [ + "temperatures_C[3] = (temperatures_C[2] + temperatures_C[4])/2\n", + "print(temperatures_C)" + ] + }, + { + "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$" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[91, 151, 149, 32, 138, 140, 144, 147, 158, 169, 176, 178, 176, 181, 194, 174, 142, 127, 122, 120, 127, 118, 113, 102]\n" + ] + } + ], + "source": [ + "temperatures_F = [round(x*1.8 + 32) for x in temperatures_C]\n", + "print(temperatures_F)" + ] + }, + { + "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": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "overheating\n" + ] + } + ], + "source": [ + "if len(hot_ones) >= 4 or m >= 80 in temperatures_C or average >= 65:\n", + " print(\"overheating\")\n", + "else:\n", + " print(\"cool.\")" + ] + }, + { + "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": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['9 A.M.', '10 A.M.', '11 A.M.', '12 P.M.', '1 P.M.', '2 P.M.', '3 P.M.']\n" + ] + } + ], + "source": [ + "more_than70 = []\n", + "for i in range(len(temperatures_C)):\n", + " if temperatures_C[i] > 70:\n", + " if i == 0:\n", + " more_than70.append('12 A.M.')\n", + " elif i > 12:\n", + " more_than70.append(str(i - 12) + ' P.M.')\n", + " elif i == 12:\n", + " more_than70.append(str(i) + ' P.M.')\n", + " else:\n", + " more_than70.append(str(i) + ' A.M.')\n", + "print(more_than70)" + ] + }, + { + "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": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There were {7} hours with temperatures above 70 C\n" + ] + } + ], + "source": [ + "print(\"There were\", {len(more_than70)}, \"hours with temperatures above 70 C\")" + ] + }, + { + "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": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "change the cooling system.\n" + ] + } + ], + "source": [ + "consexecution = 0\n", + "counter = 0\n", + "\n", + "while consexecution < 4 and len(temperatures_C) != (counter + 1):\n", + " if temperatures_C[counter] >= 70:\n", + " consexecution += 1\n", + " else:\n", + " consexecution = 0\n", + " counter += 1\n", + "\n", + " \n", + "if consexecution >= 4 or m >= 80 in temperatures_C or average >= 65:\n", + " print(\"change the cooling system.\")\n", + "else:\n", + " print(\"Cooling system effectiv.\")" + ] + }, + { + "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": 40, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "EOL while scanning string literal (, line 2)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m print(\"The average temperature in C is {round(mean(temperatures_C), 2)}, and the average temperature in F is {round(mean(temperatures_F), 2)}, \\nwhich means that, in average, the measured temperatures in F are {round(mean(temperatures_F)/mean(temperatures_C), 2)} greater than the temperatures in C.')\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n" + ] + } + ], + "source": [] + }, + { + "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": 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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/6.-Rock\342\200\223Paper\342\200\223Scissors/images/rpsls.jpg" "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/6.-Rock\342\200\223Paper\342\200\223Scissors/images/rpsls.jpg" new file mode 100644 index 000000000..82490bc16 Binary files /dev/null and "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/6.-Rock\342\200\223Paper\342\200\223Scissors/images/rpsls.jpg" differ diff --git "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" new file mode 100644 index 000000000..97389f591 --- /dev/null +++ "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" @@ -0,0 +1,556 @@ +{ + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "from typing import ForwardRef" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "gesture_options = [\"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": null, + "metadata": {}, + "outputs": [], + "source": [ + "n_rounds = 0\n", + "n_played_rounds = 0" + ] + }, + { + "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": "raw", + "metadata": {}, + "source": [ + "rounds_to_win = 0" + ] + }, + { + "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": null, + "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": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def return_cpu_choice():\n", + " variable = random.choice(gesture_options)\n", + " return variable" + ] + }, + { + "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": 1, + "metadata": {}, + "outputs": [], + "source": [ + "def ask_player_for_gesture():\n", + " print('Chose a gesture: either rock, paper, scissors')\n", + " player_choice = input()\n", + " if player_choice != \"rock\":\n", + " if player_choice != \"paper\":\n", + " if player_choice != \"scissors\":\n", + " return ask_player_for_gesture()\n", + " return player_choice" + ] + }, + { + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def get_winner(player_choise, cpu_choice):\n", + " if player_choise == \"rock\" and cpu_choice == \"scissors\":\n", + " return 2\n", + " if player_choise == \"paper\" and cpu_choice == \"scissors\":\n", + " return 1\n", + " if player_choise == \"scissors\" and cpu_choice == \"scissors\":\n", + " return 0\n", + "\n", + " if player_choise == \"rock\" and cpu_choice == \"paper\":\n", + " return 1\n", + " if player_choise == \"paper\" and cpu_choice == \"paper\":\n", + " return 0\n", + " if player_choise == \"scissors\" and cpu_choice == \"paper\":\n", + " return 2\n", + "\n", + " if player_choise == \"rock\" and cpu_choice == \"rock\":\n", + " return 0\n", + " if player_choise == \"paper\" and cpu_choice == \"rock\":\n", + " return 2\n", + " if player_choise == \"scissors\" and cpu_choice == \"rock\":\n", + " return 1\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": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def print_game_stats(player_choise, cpu_choice):\n", + " global cpu_score\n", + " global player_score\n", + " print(\"CPU chose: \", cpu_choice)\n", + " print(\"Player chose: \", player_choise)\n", + " result = get_winner(player_choise, cpu_choice)\n", + " if result == 0:\n", + " print(\"There was a tie in the round\")\n", + " if result == 1:\n", + " print(\"The CPU won the round\")\n", + " cpu_score += 1\n", + " if result == 2:\n", + " print(\"The player won the round\")\n", + " 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": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chose a gesture: either rock, paper, scissors\n", + "rock\n", + "CPU chose: paper,scissors\n", + "Player chose: rock\n", + "Round played: 1\n", + "Chose a gesture: either rock, paper, scissors\n", + "paper\n", + "CPU chose: rock\n", + "Player chose: paper\n", + "The player won the round\n", + "Round played: 2\n", + "Chose a gesture: either rock, paper, scissors\n", + "scissors\n", + "CPU chose: paper,scissors\n", + "Player chose: scissors\n", + "Round played: 3\n", + "Player Won the game!\n" + ] + } + ], + "source": [ + "import random\n", + "from typing import ForwardRef\n", + "\n", + "gesture_options = (\"rock\", \"paper,\" \"scissors\")\n", + "n_rounds = 0\n", + "n_played_rounds = 0\n", + "rounds_to_win = 0\n", + "cpu_score = 0\n", + "player_score = 0\n", + "\n", + "def return_cpu_choice():\n", + " variable = random.choice(gesture_options)\n", + " return variable\n", + "\n", + "def ask_player_for_gesture():\n", + " print('Chose a gesture: either rock, paper, scissors')\n", + " player_choice = input()\n", + " if player_choice != \"rock\":\n", + " if player_choice != \"paper\":\n", + " if player_choice != \"scissors\":\n", + " return ask_player_for_gesture()\n", + " return player_choice\n", + "\n", + "def get_winner(player_choise, cpu_choice):\n", + " if player_choise == \"rock\" and cpu_choice == \"scissors\":\n", + " return 2\n", + " if player_choise == \"paper\" and cpu_choice == \"scissors\":\n", + " return 1\n", + " if player_choise == \"scissors\" and cpu_choice == \"scissors\":\n", + " return 0\n", + "\n", + " if player_choise == \"rock\" and cpu_choice == \"paper\":\n", + " return 1\n", + " if player_choise == \"paper\" and cpu_choice == \"paper\":\n", + " return 0\n", + " if player_choise == \"scissors\" and cpu_choice == \"paper\":\n", + " return 2\n", + "\n", + " if player_choise == \"rock\" and cpu_choice == \"rock\":\n", + " return 0\n", + " if player_choise == \"paper\" and cpu_choice == \"rock\":\n", + " return 2\n", + " if player_choise == \"scissors\" and cpu_choice == \"rock\":\n", + " return 1\n", + "\n", + "def print_game_stats(player_choise, cpu_choice):\n", + " global cpu_score\n", + " global player_score\n", + " print(\"CPU chose: \", cpu_choice)\n", + " print(\"Player chose: \", player_choise)\n", + " result = get_winner(player_choise, cpu_choice)\n", + " if result == 0:\n", + " print(\"There was a tie in the round\")\n", + " if result == 1:\n", + " print(\"The CPU won the round\")\n", + " cpu_score += 1\n", + " if result == 2:\n", + " print(\"The player won the round\")\n", + " player_score += 1\n", + "\n", + "n_rounds = 3\n", + "rounds_to_win = 2\n", + "while n_played_rounds != n_rounds and (player_score != rounds_to_win and cpu_score != rounds_to_win) :\n", + " player_choice = ask_player_for_gesture()\n", + " cpu_choice = return_cpu_choice()\n", + " print_game_stats(player_choice, cpu_choice)\n", + " n_played_rounds += 1\n", + " print(\"Round played: \", n_played_rounds)\n", + "\n", + "if cpu_score > player_score:\n", + " print(\"CPU Won the game!\")\n", + "if cpu_score < player_score:\n", + " print(\"Player Won the game!\")\n", + "if cpu_score == player_score:\n", + " print(\"There was a tie in the game!\")" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "if cpu_score > player_score:\n", + " print(\"CPU Won the game!\")\n", + "if cpu_score < player_score:\n", + " print(\"Player Won the game!\")\n", + "if cpu_score == player_score:\n", + " print(\"There was a tie in the game!\")" + ] + }, + { + "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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "How many rounds you want to play? It has to be an odd number: 3\n", + "Alrighty! Let's play 3 rounds.\n", + "Chose a gesture: either rock, paper, scissors, lizard, spock\n", + "spock\n", + "CPU chose: lizard\n", + "Player chose: spock\n", + "The CPU won the round\n", + "Round played: 1\n", + "Chose a gesture: either rock, paper, scissors, lizard, spock\n", + "lizard\n", + "CPU chose: lizard\n", + "Player chose: lizard\n", + "There was a tie in the round\n", + "Round played: 2\n", + "Chose a gesture: either rock, paper, scissors, lizard, spock\n", + "paper\n", + "CPU chose: paper\n", + "Player chose: paper\n", + "There was a tie in the round\n", + "Round played: 3\n", + "CPU Won the game!\n" + ] + } + ], + "source": [ + "import random\n", + "from typing import ForwardRef\n", + "\n", + "gesture_options = (\"rock\", \"paper\", \"scissors\", \"lizard\", \"spock\")\n", + "n_rounds = 0\n", + "n_played_rounds = 0\n", + "rounds_to_win = 0\n", + "cpu_score = 0\n", + "player_score = 0\n", + "\n", + "rounds_to_play = input(\"How many rounds you want to play? It has to be an odd number: \")\n", + "\n", + "try:\n", + " rounds_to_play = int(rounds_to_play)\n", + " if rounds_to_play % 2 == 0:\n", + " print(\"That is so NOT an odd number\")\n", + " rounds_to_play = 0\n", + " elif rounds_to_play > 10:\n", + " print(\"Try please less than 10\")\n", + " rounds_to_play = 0\n", + " else:\n", + " print(\"Alrighty! Let's play \", int(rounds_to_play), \" rounds.\")\n", + "except ValueError:\n", + " print(\"To play \", rounds_to_play, \" rounds we'd have to slice your hand in pieces, honey.\")\n", + " rounds_to_play = 0\n", + "\n", + "\n", + "def return_cpu_choice():\n", + " variable = random.choice(gesture_options)\n", + " return variable\n", + "\n", + "def ask_player_for_gesture():\n", + " print('Chose a gesture: either rock, paper, scissors, lizard, spock')\n", + " player_choice = input()\n", + " if player_choice != \"rock\":\n", + " if player_choice != \"paper\":\n", + " if player_choice != \"scissors\":\n", + " if player_choice != \"lizard\":\n", + " if player_choice != \"spock\":\n", + " return ask_player_for_gesture()\n", + " return player_choice\n", + "\n", + "def get_winner(player_choise, cpu_choice):\n", + " if player_choise == \"rock\" and cpu_choice == \"scissors\":\n", + " return 2\n", + " if player_choise == \"paper\" and cpu_choice == \"scissors\":\n", + " return 1\n", + " if player_choise == \"scissors\" and cpu_choice == \"scissors\":\n", + " return 0\n", + "\n", + " if player_choise == \"rock\" and cpu_choice == \"paper\":\n", + " return 1\n", + " if player_choise == \"paper\" and cpu_choice == \"paper\":\n", + " return 0\n", + " if player_choise == \"scissors\" and cpu_choice == \"paper\":\n", + " return 2\n", + "\n", + " if player_choise == \"rock\" and cpu_choice == \"rock\":\n", + " return 0\n", + " if player_choise == \"paper\" and cpu_choice == \"rock\":\n", + " return 2\n", + " if player_choise == \"scissors\" and cpu_choice == \"rock\":\n", + " return 1\n", + " \n", + " if player_choise == \"rock\" and cpu_choice == \"lizard\":\n", + " return 2\n", + " if player_choise == \"spock\" and cpu_choice == \"lizard\":\n", + " return 1\n", + " if player_choise == \"lizard\" and cpu_choice == \"lizard\":\n", + " return 0\n", + " \n", + " if player_choise == \"paper\" and cpu_choice == \"spock\":\n", + " return 2\n", + " if player_choise == \"scissors\" and cpu_choice == \"spock\":\n", + " return 1\n", + " if player_choise == \"spock\" and cpu_choice == \"spock\":\n", + " return 0\n", + " \n", + " if player_choise == \"lizard\" and cpu_choice == \"paper\":\n", + " return 2\n", + " if player_choise == \"paper\" and cpu_choice == \"lizard\":\n", + " return 1\n", + " \n", + " if player_choise == \"scissors\" and cpu_choice == \"lizard\":\n", + " return 2\n", + " if player_choise == \"lizard\" and cpu_choice == \"scissors\":\n", + " return 1\n", + " \n", + "def print_game_stats(player_choise, cpu_choice):\n", + " global cpu_score\n", + " global player_score\n", + " print(\"CPU chose: \", cpu_choice)\n", + " print(\"Player chose: \", player_choise)\n", + " result = get_winner(player_choise, cpu_choice)\n", + " if result == 0:\n", + " print(\"There was a tie in the round\")\n", + " if result == 1:\n", + " print(\"The CPU won the round\")\n", + " cpu_score += 1\n", + " if result == 2:\n", + " print(\"The player won the round\")\n", + " player_score += 1\n", + "\n", + "n_rounds = rounds_to_play\n", + "rounds_to_win = 2\n", + "while n_played_rounds != n_rounds and (player_score != rounds_to_win and cpu_score != rounds_to_win) :\n", + " player_choice = ask_player_for_gesture()\n", + " cpu_choice = return_cpu_choice()\n", + " print_game_stats(player_choice, cpu_choice)\n", + " n_played_rounds += 1\n", + " print(\"Round played: \", n_played_rounds)\n", + "\n", + "if cpu_score > player_score:\n", + " print(\"CPU Won the game!\")\n", + "if cpu_score < player_score:\n", + " print(\"Player Won the game!\")\n", + "if cpu_score == player_score:\n", + " print(\"There was a tie in the game!\")" + ] + }, + { + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors-checkpoint.ipynb" "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors-checkpoint.ipynb" new file mode 100644 index 000000000..cbcbe9a89 --- /dev/null +++ "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors-checkpoint.ipynb" @@ -0,0 +1,256 @@ +{ + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "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": null, + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "n_rounds = input(\"rounds you want to play? >>> \")\n", + "try:\n", + " n_rounds = int(n_rounds)\n", + " if n_rounds % 2 == 0:\n", + " print(\"That is not a number...\")\n", + " n_rounds = 0\n", + " elif n_rounds > 10:\n", + " n_rounds = 0\n", + " else:\n", + " print(\"play \", int(n_rounds), \" rounds.\")" + ] + }, + { + "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": "raw", + "metadata": {}, + "source": [ + "rounds_to_win = input(n_rounds)" + ] + }, + { + "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": null, + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "### w should be the list of posible gestures\n", + "def T800(w):\n", + " return choice(w);" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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": 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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/2.-Statistics/Probability(Basic an Intermediate) Graded Quiz.jpg b/2.-Statistics/Probability(Basic an Intermediate) Graded Quiz.jpg new file mode 100644 index 000000000..a3b71405a Binary files /dev/null and b/2.-Statistics/Probability(Basic an Intermediate) Graded Quiz.jpg differ diff --git a/2.-Statistics/Screens01.png b/2.-Statistics/Screens01.png new file mode 100644 index 000000000..9f2f6e7ae Binary files /dev/null and b/2.-Statistics/Screens01.png differ diff --git a/2.-Statistics/Screens02.png b/2.-Statistics/Screens02.png new file mode 100644 index 000000000..231549b94 Binary files /dev/null and b/2.-Statistics/Screens02.png differ diff --git a/2.-Statistics/Screens03.png b/2.-Statistics/Screens03.png new file mode 100644 index 000000000..202f35d10 Binary files /dev/null and b/2.-Statistics/Screens03.png differ diff --git a/2.-Statistics/Screens04.png b/2.-Statistics/Screens04.png new file mode 100644 index 000000000..df0c4f2b0 Binary files /dev/null and b/2.-Statistics/Screens04.png differ diff --git a/2.-Statistics/Screens05.png b/2.-Statistics/Screens05.png new file mode 100644 index 000000000..0624c62a0 Binary files /dev/null and b/2.-Statistics/Screens05.png differ diff --git a/2.-Statistics/Screens06.png b/2.-Statistics/Screens06.png new file mode 100644 index 000000000..2535eeb42 Binary files /dev/null and b/2.-Statistics/Screens06.png differ diff --git a/2.-Statistics/Screens07.png b/2.-Statistics/Screens07.png new file mode 100644 index 000000000..547642187 Binary files /dev/null and b/2.-Statistics/Screens07.png differ diff --git a/2.-Statistics/Screens08.png b/2.-Statistics/Screens08.png new file mode 100644 index 000000000..99eb5fd84 Binary files /dev/null and b/2.-Statistics/Screens08.png differ diff --git a/2.-Statistics/Screens09.png b/2.-Statistics/Screens09.png new file mode 100644 index 000000000..6b342ee0b Binary files /dev/null and b/2.-Statistics/Screens09.png differ diff --git a/2.-Statistics/Screens10.png b/2.-Statistics/Screens10.png new file mode 100644 index 000000000..04b50f6c8 Binary files /dev/null and b/2.-Statistics/Screens10.png differ diff --git a/2.-Statistics/Screens11.png b/2.-Statistics/Screens11.png new file mode 100644 index 000000000..8c116884a Binary files /dev/null and b/2.-Statistics/Screens11.png differ diff --git a/2.-Statistics/Screens12.png b/2.-Statistics/Screens12.png new file mode 100644 index 000000000..43534e6d6 Binary files /dev/null and b/2.-Statistics/Screens12.png differ diff --git a/2.-Statistics/Screens13.png b/2.-Statistics/Screens13.png new file mode 100644 index 000000000..06b2a12f4 Binary files /dev/null and b/2.-Statistics/Screens13.png differ diff --git a/2.-Statistics/Screens14.png b/2.-Statistics/Screens14.png new file mode 100644 index 000000000..009621829 Binary files /dev/null and b/2.-Statistics/Screens14.png differ diff --git a/robot.md b/robot.md new file mode 100644 index 000000000..e69de29bb