diff --git a/1.-Python[Nathy]/1.-Snail-and-Well/snail-and-well.ipynb b/1.-Python[Nathy]/1.-Snail-and-Well/snail-and-well.ipynb new file mode 100644 index 000000000..4f0a85a9e --- /dev/null +++ b/1.-Python[Nathy]/1.-Snail-and-Well/snail-and-well.ipynb @@ -0,0 +1,249 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# The Snail and the Well\n", + "\n", + "A snail falls at the bottom of a 125 cm well. Each day the snail rises 30 cm. But at night, while sleeping, slides 20 cm because the walls are wet. How many days does it take for the snail to escape the well?\n", + "\n", + "**Hint**: The snail gets out of the well when it surpasses the 125cm of height.\n", + "\n", + "## Tools\n", + "\n", + "1. Loop: **while**\n", + "2. Conditional statements: **if-else**\n", + "3. Function: **print()**\n", + "\n", + "## Tasks\n", + "\n", + "#### 1. Assign the challenge data to variables with representative names: `well_height`, `daily_distance`, `nightly_distance` and `snail_position`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "well_height=125\n", + "daily_distance=30\n", + "nightly_distance=20\n", + "snail_position=[]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Create a variable `days` to keep count of the days that pass until the snail escapes the well. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "days=[]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the solution to the challenge using the variables defined above. " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "snail_position=daily_distance-nightly_distance\n", + "days=well_height/snail_position" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Print the solution." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "El caracol saldrá del pozo luego de 12.5 días\n" + ] + } + ], + "source": [ + "print(\"El caracol saldrá del pozo luego de\",days,\"días\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus\n", + "The distance traveled by the snail each day is now defined by a list.\n", + "```\n", + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "```\n", + "On the first day, the snail rises 30cm but during the night it slides 20cm. On the second day, the snail rises 21cm but during the night it slides 20cm, and so on. \n", + "\n", + "#### 1. How many days does it take for the snail to escape the well?\n", + "Follow the same guidelines as in the previous challenge.\n", + "\n", + "**Hint**: Remember that the snail gets out of the well when it surpasses the 125cm of height." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "El caracol saldrá del pozo luego de 6 días\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "i=0\n", + "distance=0\n", + "vector_distance=[]\n", + "while distance" + ] + }, + { + "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": 98, + "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=[]" + ] + }, + { + "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": 99, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_wins=0\n", + "saruman_wins=0\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Using the lists of spells of both sorcerers, update variables `gandalf_wins` and `saruman_wins` to count the number of times each sorcerer wins a clash. " + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "length=len(gandalf)\n", + "for i in range(length):\n", + " if gandalf[i]saruman[i]:\n", + " gandalf_wins+=1\n", + " \n", + " else:\n", + " gandalf_wins+=1\n", + " saruman_wins+=1\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Who won the battle?\n", + "Print `Gandalf wins`, `Saruman wins` or `Tie` depending on the result. " + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "El ganador es Gandalf\n" + ] + } + ], + "source": [ + "if gandalf_winssaruman_wins:\n", + " print(\"El ganador es Gandalf\")\n", + "else:\n", + " print(\"Empate\")" + ] + }, + { + "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": 92, + "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=[]\n", + "\n" + ] + }, + { + "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": 93, + "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": 94, + "metadata": {}, + "outputs": [], + "source": [ + "gandalf_power=[]\n", + "saruman_power=[]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. The battle starts! Using the variables you've created above, code the execution of spell clashes. Remember that a sorcerer wins if he succeeds in winning 3 spell clashes in a row. \n", + "If a clash ends up in a tie, the counter of wins in a row is not restarted to 0. Remember to print who is the winner of the battle. " + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ganó Gandalf\n" + ] + } + ], + "source": [ + "\n", + "\n", + "for i in range(0,len(gandalf)):\n", + " g=gandalf[i] #Para gandalf\n", + " G=POWER.get(g)\n", + " gandalf_power.append(G)\n", + " #Para saruman\n", + " s=saruman[i]\n", + " S=POWER.get(s)\n", + " saruman_power.append(S)\n", + "j=0\n", + "while j" + ] + }, + { + "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": 21, + "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": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hay 9 paradas\n" + ] + } + ], + "source": [ + "l=len(stops)\n", + "print(\"Hay\", l, \"paradas\")\n" + ] + }, + { + "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": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[10, 13, 11, 10, 14, 10, 7, 5, 4]" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pasajeros=[]\n", + "entran=[]\n", + "salen=[]\n", + "for i in range(0,l):\n", + " a=stops[i]\n", + " entran.insert(i,a[0])\n", + " salen.insert(i,a[1])\n", + "\n", + "for j in range(0,l):\n", + " pasajeros.insert(j,entran[j]-salen[j])\n", + "P=[]\n", + "P.append(pasajeros[0])\n", + "for k in range(0,l-1):\n", + " P.append(P[k]+pasajeros[k+1])\n", + " \n", + "P" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Find the maximum occupation of the bus." + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(P)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Calculate the average occupation. And the standard deviation." + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La media de ocupación es 9.333333333333334 ,y la desviación estándar es 3.391164991562634\n" + ] + } + ], + "source": [ + "import statistics\n", + "average=sum(P)/len(P)\n", + "desv=statistics.stdev(P)\n", + "print(\"La media de ocupación es\",average,\",y la desviación estándar es\",desv)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python[Nathy]/4.-Robin-Hood/images/arrows.jpg b/1.-Python[Nathy]/4.-Robin-Hood/images/arrows.jpg new file mode 100644 index 000000000..88f1ba640 Binary files /dev/null and b/1.-Python[Nathy]/4.-Robin-Hood/images/arrows.jpg differ diff --git a/1.-Python[Nathy]/4.-Robin-Hood/robin-hood.ipynb b/1.-Python[Nathy]/4.-Robin-Hood/robin-hood.ipynb new file mode 100644 index 000000000..a80e38668 --- /dev/null +++ b/1.-Python[Nathy]/4.-Robin-Hood/robin-hood.ipynb @@ -0,0 +1,243 @@ +{ + "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": 5, + "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": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A continuación se muestran los puntos dónde se arojó más de una flecha, indicando además el cuadrante al que corresponde {((-3, 2), 'Q2'), ((2, 2), 'Q1'), ((4, 5), 'Q1'), ((5, 7), 'Q1')}\n" + ] + } + ], + "source": [ + "flecha=[]\n", + "P=sorted(points) #ordenar los puntos\n", + "for i in range(0,len(p)-1):\n", + " if P[i]==P[i+1]:\n", + " m=P[i]\n", + " a=m[0]\n", + " b=m[1]\n", + " #para ver en qué parte del plano se encuentra:\n", + " if a>0:\n", + " if b>0:\n", + " t=(m,'Q1')\n", + " if b<0:\n", + " t=(m,'Q4')\n", + " if b==0:\n", + " t=(m,'En el eje X, entre Q1 y Q4')\n", + " if a<0:\n", + " if b>0:\n", + " t=(m,'Q2')\n", + " if b<0:\n", + " t=(m,'Q3')\n", + " if b==0:\n", + " t=(m,'En el eje X, entre Q2 y Q3')\n", + " if a==0:\n", + " if b>0:\n", + " t=(m,'En el eje Y, entre Q1 y Q2')\n", + " if b<0:\n", + " t=(m,'En el eje Y, entre Q3 y Q4')\n", + " if b==0:\n", + " t=(m,'Centro')\n", + " \n", + " \n", + " flecha.append(t) #almacena la tupla (coordenada,ubicación en el plano)\n", + "\n", + "#para eliminar los elementos repetidos de 'flecha':\n", + "flecha=set(flecha)\n", + "print(\"A continuación se muestran los puntos dónde se arojó más de una flecha, indicando además el cuadrante al que corresponde\",flecha)" + ] + }, + { + "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": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "En el cuadrante 1 cayeron 10 flechas\n", + "En el cuadrante 2 cayeron 6 flechas\n", + "En el cuadrante 3 cayeron 2 flechas\n", + "En el cuadrante 4 cayeron 2 flechas\n" + ] + } + ], + "source": [ + "Q1=0\n", + "Q2=0\n", + "Q3=0\n", + "Q4=0\n", + "for i in range(0,len(points)):\n", + " m=points[i]\n", + " a=m[0]\n", + " b=m[1]\n", + " #para ver en qué parte del plano se encuentra:\n", + " if a>0:\n", + " if b>0:\n", + " Q1+=1\n", + " if b<0:\n", + " Q4+=1\n", + "\n", + " if a<0:\n", + " if b>0:\n", + " Q2+=1\n", + " if b<0:\n", + " Q3+=1\n", + "print(\"En el cuadrante 1 cayeron\",Q1,\"flechas\")\n", + "print(\"En el cuadrante 2 cayeron\",Q2,\"flechas\")\n", + "print(\"En el cuadrante 3 cayeron\",Q3,\"flechas\")\n", + "print(\"En el cuadrante 4 cayeron\",Q4,\"flechas\")" + ] + }, + { + "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": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Se obtuvo la distancia mínima de 2.0 en: [(0, 2), (0, -2)]\n" + ] + } + ], + "source": [ + "from scipy.spatial import distance\n", + "centro=[(0,0)]\n", + "D=[] #para guardar las distancias\n", + "for i in range(0,len(points)):\n", + " D.append(distance.euclidean(centro,points[i])) #va guardando las distancias\n", + "m=min(D) \n", + "posicion=[p for p, v in enumerate(D) if v==2.0] #indica la posición dónde los puntos obtuvieron la distancia mínima\n", + "\n", + "puntoM=[] #guarda los puntos dónde hubo mínima distancia\n", + "for j in range(0,len(posicion)):\n", + " puntoM.append(points[posicion[j]])\n", + "\n", + "print(\"Se obtuvo la distancia mínima de\",m,\"en:\",puntoM)\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. If the archery target has a radius of 9, calculate the number of arrows that won't hit the target. \n", + "**Hint**: Use the function created in step 3. " + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cayeron 2 flechas fuera del radio\n" + ] + } + ], + "source": [ + "from scipy.spatial import distance\n", + "centro=[(0,0)]\n", + "radio=9\n", + "fuera=0\n", + "for i in range(0,len(points)):\n", + " d=distance.euclidean(centro,points[i]) #va guardando las distancias\n", + " if d>radio:\n", + " fuera+=1\n", + "print(\"Cayeron\",fuera,\"flechas fuera del radio\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python[Nathy]/5.-Temperature-Processor/temperature.ipynb b/1.-Python[Nathy]/5.-Temperature-Processor/temperature.ipynb new file mode 100644 index 000000000..2f2b70e62 --- /dev/null +++ b/1.-Python[Nathy]/5.-Temperature-Processor/temperature.ipynb @@ -0,0 +1,366 @@ +{ + "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": 1, + "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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "tmin=min(temperatures_C)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Find the maximum temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "tmax=max(temperatures_C)" + ] + }, + { + "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": 12, + "metadata": {}, + "outputs": [], + "source": [ + "listMayor=[]\n", + "for i in range(0,len(temperatures_C)):\n", + " if temperatures_C[i]>70:\n", + " listMayor.append(temperatures_C[i])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Find the average temperature of the day and store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "promedio=sum(temperatures_C)/len(temperatures_C)\n" + ] + }, + { + "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": 46, + "metadata": {}, + "outputs": [], + "source": [ + "temp3=temperatures_C[3] #ubicar elemento de las 3am\n", + "temperatures_C.remove(temp3) #eliminar elemento de las 3am\n", + "media_T=sum(temperatures_C)/len(temperatures_C) #media de T\n", + "#simplemente se colocará el valor de las 3AM como la media de T. Puede generar distorsiones pero es una forma de estimar el valor.\n", + "temperatures_C.insert(3,media_T) #insertar media a las 3 am" + ] + }, + { + "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": 47, + "metadata": {}, + "outputs": [], + "source": [ + "def cels_fahr(c): #crear función que cambie de Celsius a Fahrenheit\n", + " return (c * 1.8) + 32\n", + "Fahrenheit=[] #definir donde se almacenarán las temperaturas convertidas\n", + "\n", + "for i in range(0,len(temperatures_C)):\n", + " Fahrenheit.append(cels_fahr(temperatures_C[i]))\n", + "\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 7. Make a decision!\n", + "Now it's time to make a decision taking into account what you have seen until now. \n", + "\n", + "Remember that if one of the following events occurs, then the cooling system needs to be replaced for a new one to avoid damaging the processor.\n", + "* More than 4 temperatures are greater than or equal to 70ºC.\n", + "* Any temperature is above 80ºC.\n", + "* The average temperature exceeds 65ºC.\n", + "\n", + "#### To make your decision, check if any of the three conditions above is met. You might need to use some of the variables you created in steps 1 to 6. Print a message to show if the cooling system needs to be changed or not." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Debe reemplazar el sistema, hay más de 4 temperaturas mayores a 70°C.\n", + "Hay temperaturas superiores a 80°C. Cambie el sistema.\n" + ] + } + ], + "source": [ + "#verificar si alguna temperatura supera los 80:\n", + "b=0\n", + "for i in range(0,len(listMayor)):\n", + " if listMayor[i]>80:\n", + " b+=1\n", + " \n", + "\n", + "if len(listMayor)>4: #ver si hay más de 4 temperaturas mayores a 70°\n", + " print(\"Debe reemplazar el sistema, hay más de 4 temperaturas mayores a 70°C.\")\n", + "if b>0:\n", + " print(\"Hay temperaturas superiores a 80°C. Cambie el sistema.\")\n", + "if promedio>65:\n", + " print(\"La temperatura media supera los 65°C. Debe cambiar el sistema.\")\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus\n", + "\n", + "The company has decided that the decision you made is not valid. They want you to analyze the data again but this time, the conditions that need to be met in order to change the cooling system are different.\n", + "\n", + "This time, if one of the following events occurs, then the cooling system needs to be replaced:\n", + "* The temperature is greater than 70ºC during more than 4 consecutive hours.\n", + "* Any temperature is above 80ºC.\n", + "* The average temperature exceeds 65ºC.\n", + "\n", + "Follow the steps so that you can make the decision.\n", + "\n", + "#### 1. Create a list with the hours where the temperature is greater than 70ºC. Store it in a variable." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "hora=[]\n", + "for i in range(0,len(temperatures_C)):\n", + " if temperatures_C[i]>70:\n", + " hora.append(i)" + ] + }, + { + "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": 50, + "metadata": {}, + "outputs": [], + "source": [ + "consecutivo=0\n", + "for i in range(0,len(hora)-1):\n", + " if hora[i]+1==hora[i+1]:\n", + " consecutivo+=1" + ] + }, + { + "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": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Debe reemplazar el sistema, hay más de 4 temperaturas consecutivas mayores a 70°C.\n", + "Hay temperaturas superiores a 80°C. Cambie el sistema.\n" + ] + } + ], + "source": [ + "\n", + "if consecutivo>4: #ver si hay más de 4 temperaturas consecutivas mayores a 70°\n", + " print(\"Debe reemplazar el sistema, hay más de 4 temperaturas consecutivas mayores a 70°C.\")\n", + "if b>0: #b se definió en el item 7 de la sección anterior\n", + " print(\"Hay temperaturas superiores a 80°C. Cambie el sistema.\")\n", + "if promedio>65:\n", + " print(\"La temperatura media supera los 65°C. Debe cambiar el sistema.\")\n", + "\n" + ] + }, + { + "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": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La media de las temperaturas en grados Celsius es 62.869565217391305 , lo cual al transformarlo a grados Fahrenheit da exactamente la media de las temperaturas en °F, lo cual es 145.16521739130434\n" + ] + } + ], + "source": [ + "promedio=sum(temperatures_C)/len(temperatures_C)\n", + "prom_F=sum(Fahrenheit)/len(Fahrenheit)\n", + "\n", + "print(\"La media de las temperaturas en grados Celsius es \",promedio,\", lo cual al transformarlo a grados Fahrenheit da exactamente la media de las temperaturas en °F, lo cual es \",prom_F)" + ] + }, + { + "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": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La desviación estándar de las temperaturas en °C es 14.947165931245344 , y en °F es 26.90489867624162 . Con esto se muestra que al hacer la transformación a °F, se obtiene mayor dispersión entre los datos.\n" + ] + } + ], + "source": [ + "import statistics\n", + "desv_C=statistics.stdev(temperatures_C)\n", + "desv_F=statistics.stdev(Fahrenheit)\n", + "print(\"La desviación estándar de las temperaturas en °C es \",desv_C,\", y en °F es \",desv_F, \". Con esto se muestra que al hacer la transformación a °F, se obtiene mayor dispersión entre los datos.\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/1.-Python[Nathy]/6.-Rock\342\200\223Paper\342\200\223Scissors/images/rpsls.jpg" "b/1.-Python[Nathy]/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[Nathy]/6.-Rock\342\200\223Paper\342\200\223Scissors/images/rpsls.jpg" differ diff --git "a/1.-Python[Nathy]/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" "b/1.-Python[Nathy]/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" new file mode 100644 index 000000000..31bb03781 --- /dev/null +++ "b/1.-Python[Nathy]/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" @@ -0,0 +1,541 @@ +{ + "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": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import random" + ] + }, + { + "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": 44, + "metadata": {}, + "outputs": [], + "source": [ + "opciones=['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": 31, + "metadata": {}, + "outputs": [], + "source": [ + "def veces():\n", + " n_rounds=2 #se le asigna un número par para que entre al ciclo\n", + " while n_rounds%2==0:\n", + " print('Ingrese el número de veces que se va a jugar. Debe ser un número entero impar')\n", + " n_rounds=int(input())\n", + " return n_rounds\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Create a variable called `rounds_to_win` to store the number of rounds that a player must win to win the game.\n", + "**Hint**: the value stored in `rounds_to_win` depends on the value of `n_rounds`. " + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "def win():\n", + " rounds_to_win=n_rounds+1\n", + " while rounds_to_win>n_rounds:\n", + " print(\"Ingrese el número de rondas que un participante debe superar para ganar el juego. Recuerde que debe ser menor o igual al número de veces que se va a jugar\")\n", + " rounds_to_win=int(input())\n", + " return rounds_to_win" + ] + }, + { + "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": 5, + "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": 36, + "metadata": {}, + "outputs": [], + "source": [ + "def jugar_cpu(opciones):\n", + " jugada = opciones[random.randint(0,len(opciones)-1)]\n", + " return jugada\n" + ] + }, + { + "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": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Escriba su elección: rock\n" + ] + }, + { + "data": { + "text/plain": [ + "'rock'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def jugador(opciones):\n", + " elecc='p'\n", + " while elecc not in opciones:\n", + " elecc=input(\"Escriba su elección: \")\n", + " \n", + " return elecc\n" + ] + }, + { + "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": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def ganador(player_score,cpu_score):\n", + "#comparar para ver quién gana\n", + " if player_score>=rounds_to_win:\n", + " resultado=2 #gana el jugador\n", + " elif cpu_score>=rounds_to_win:\n", + " resultado=1 #gana el cpu\n", + " else:\n", + " resultado=0 #empate\n", + " \n", + " return resultado \n", + " \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": 10, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "def juego(modo,opciones): #modo indica si quiero detener la ejecución cuando se llegue \n", + " #al mínimo de puntos requeridos para ganar, ya sea del cpu o del usuario\n", + " #modo es 1 para sí, otro para no\n", + " player_score=0\n", + " cpu_score=0\n", + " for i in range(0,n_rounds):\n", + " eleccion=jugador(opciones)\n", + " cpu=jugar_cpu(opciones)\n", + " print(\"Jugada del CPU:\",cpu)\n", + " if cpu=='rock':\n", + " if eleccion=='paper':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='scissors':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " \n", + " elif cpu=='paper':\n", + " if eleccion=='scissors':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='rock':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " else:\n", + " if eleccion=='rock':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='paper':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " \n", + " if modo==1:\n", + " #a continuación se tiene que si ya un jugador o el cpu completaron los puntos \n", + " #para ganar, termina el juego\n", + " if player_score==rounds_to_win:\n", + " break\n", + " if cpu_score==rounds_to_win:\n", + " break\n", + "\n", + " \n", + " \n", + " \n", + " g=[player_score,cpu_score]\n", + " \n", + "\n", + " return g \n", + " \n" + ] + }, + { + "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": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bienvenid@. Juego piedra, papel o tijeras. Va a escribir su elección ya sea rock, paper o scissors. Si lo escribe mal el programa se repetirá hasta que ingrese una opción válida\n", + "Ingrese el número de veces que se va a jugar. Debe ser un número entero impar\n", + "5\n", + "Ingrese el número de rondas que un participante debe superar para ganar el juego. Recuerde que debe ser menor o igual al número de veces que se va a jugar\n", + "2\n", + "Escriba su elección: rock\n", + "Jugada del CPU: scissors\n", + "Punto para el jugador\n", + "Escriba su elección: rock\n", + "Jugada del CPU: scissors\n", + "Punto para el jugador\n", + "¡Felicidades, ganaste!\n" + ] + } + ], + "source": [ + "print(\"Bienvenid@. Juego piedra, papel o tijeras. Va a escribir su elección ya sea rock, paper o scissors. Si lo escribe mal el programa se repetirá hasta que ingrese una opción válida\")\n", + "n_rounds=veces() #dice cuántas jugadas son permitidas\n", + "rounds_to_win=win() #indica en qué puntaje ya se gana y finaliza el juego\n", + "j=juego(1,opciones) #se colocó 1 porque cuando alguno llega al mínimo requerido para ganar\n", + "#finaliza el juego\n", + "g=ganador(j[0],j[1])\n", + "if g==0:\n", + " print(\"Fin de juego. EMPATE\")\n", + "elif g==1:\n", + " print(\"Fin de juego. Ganó el CPU, tú pierdes\")\n", + "else:\n", + " print(\"¡Felicidades, ganaste!\")" + ] + }, + { + "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": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bienvenid@. Debe escribir rock, paper o scissors´según sea su elección cuando el programa se lo indique.\n", + "Ingrese el número de veces que se va a jugar. Debe ser un número entero impar\n", + "3\n", + "Escriba su elección: rock\n", + "Jugada del CPU: scissors\n", + "Punto para el jugador\n", + "Escriba su elección: rock\n", + "Jugada del CPU: scissors\n", + "Punto para el jugador\n", + "Escriba su elección: rock\n", + "Jugada del CPU: rock\n", + "Empate en la jugada\n", + "2 0\n", + "Felicidades ¡Ganaste!. Tu puntuación fue 2 , mientras que CPU obtuvo 0\n" + ] + } + ], + "source": [ + "print(\"Bienvenid@. Debe escribir rock, paper o scissors´según sea su elección cuando el programa se lo indique.\")\n", + "n_rounds=veces()\n", + "J=juego(0,opciones)#marco 0 porque se quiere que el juego continúe hasta el final y luego \n", + "#indique el puntaje de cada quién\n", + "a=J[0]\n", + "b=J[1]\n", + "print(a,b)\n", + "\n", + "#gana el que tiene mayor puntaje, si tienen igual puntaje hay empate:\n", + "if J[0]J[1]: #jugador tiene más puntos\n", + " print(\"Felicidades ¡Ganaste!. Tu puntuación fue \",J[0],\", mientras que CPU obtuvo \",J[1])\n", + "else:\n", + " print(\"La puntuación quedó\",J[0],\"-\",J[1],\". EMPATE\")\n", + "\n" + ] + }, + { + "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": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bienvenid@. Cuando se le indique debe escribir rock, paper, scissors, spock, o lizard. Esa será su jugada.\n", + "Ingrese el número de veces que se va a jugar. Debe ser un número entero impar\n", + "5\n", + "Escriba su elección: rock\n", + "Jugada del CPU: paper\n", + "Punto para el CPU\n", + "Escriba su elección: paper\n", + "Jugada del CPU: rock\n", + "Punto para el jugador\n", + "Escriba su elección: \n", + "Escriba su elección: lizard\n", + "Jugada del CPU: scissors\n", + "Punto para el CPU\n", + "Escriba su elección: spock\n", + "Jugada del CPU: paper\n", + "Punto para el CPU\n", + "Escriba su elección: paper\n", + "Jugada del CPU: rock\n", + "Punto para el jugador\n", + "2 3\n", + "Perdiste. Gana el CPU. Puntaje final: 3 para el CPU, 2 para tí\n" + ] + } + ], + "source": [ + "print(\"Bienvenid@. Cuando se le indique debe escribir rock, paper, scissors, spock, o lizard. Esa será su jugada.\")\n", + "#añadir 2 elementos más a la lista opciones:\n", + "opciones.extend(['lizard','spock'])\n", + "\n", + "#modificar función juego:\n", + "n_rounds=veces()\n", + "def juego_M(opciones):\n", + " player_score=0\n", + " cpu_score=0\n", + " for i in range(0,n_rounds):\n", + " eleccion=jugador(opciones)\n", + " cpu=jugar_cpu(opciones)\n", + " print(\"Jugada del CPU:\",cpu)\n", + " if cpu=='rock':\n", + " if eleccion=='paper' or eleccion=='spock':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='scissors'or eleccion=='lizard':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " \n", + " elif cpu=='paper':\n", + " if eleccion=='scissors' or eleccion=='lizard':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='rock' or eleccion=='spock':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " elif cpu=='scissors':\n", + " if eleccion=='rock' or eleccion=='spock':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='paper' or eleccion=='lizard':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " \n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " elif cpu=='spock':\n", + " if eleccion=='paper' or eleccion=='lizard':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='rock' or eleccion=='scissors':\n", + " cpu_score+=1\n", + " print(\"Punto para el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " else:\n", + " if eleccion=='rock' or eleccion=='scissors':\n", + " player_score+=1\n", + " print(\"Punto para el jugador\")\n", + " elif eleccion=='paper' or eleccion=='spock':\n", + " cpu_score+=1\n", + " print(\"Punto pra el CPU\")\n", + " else:\n", + " print(\"Empate en la jugada\")\n", + " \n", + " \n", + " \n", + " \n", + " g=[player_score,cpu_score]\n", + " \n", + "\n", + " return g \n", + " \n", + "J=juego_M(opciones) #aplicar función juego modificada\n", + "a=J[0]\n", + "b=J[1]\n", + "print(a,b)\n", + "\n", + "#gana el que tiene mayor puntaje, si tienen igual puntaje hay empate:\n", + "if J[0]J[1]: #jugador tiene más puntos\n", + " print(\"Felicidades ¡Ganaste!. Tu puntuación fue \",J[0],\", mientras que CPU obtuvo \",J[1])\n", + "else:\n", + " print(\"La puntuación quedó\",J[0],\"-\",J[1],\". EMPATE\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1.-Python[Nathy]/README.md b/1.-Python[Nathy]/README.md new file mode 100644 index 000000000..c40f253fc --- /dev/null +++ b/1.-Python[Nathy]/README.md @@ -0,0 +1,13 @@ +#### Python +This directory includes a bunch of folders. Each folder is a different challenge and it contains a Jupyter Notebook file (`.ipynb`). Open the notebook file in browser. Then, follow the step-by-step instructions to solve the challenge in the interactive coding environment. + +Solve the challenges following the order suggested below. + +**Suggested Order Based on Difficulty** + +1. [Snail and well](./1.-Python/1.-Snail-and-Well) +1. [Duel of sorcerers](./1.-Python/2.-Duel-of-Sorcerers) +1. [Bus](./1.-Python/3.-Bus) +1. [Robin Hood](./1.-Python/4.-Robin-Hood) +1. [Processor temperature](./1.-Python/5.-Temperature-Processor) +1. [Rock Paper Scissors](./1.-Python/6.-Rock–Paper–Scissors) diff --git a/2.-Statistics[Nathy]/Ejercicios.pdf b/2.-Statistics[Nathy]/Ejercicios.pdf new file mode 100644 index 000000000..52aa2bbcd Binary files /dev/null and b/2.-Statistics[Nathy]/Ejercicios.pdf differ diff --git a/2.-Statistics[Nathy]/README.md b/2.-Statistics[Nathy]/README.md new file mode 100644 index 000000000..539464b01 --- /dev/null +++ b/2.-Statistics[Nathy]/README.md @@ -0,0 +1,33 @@ +# Statistics +The statistics challenge consists of completing the `Data Science Math Skills` course in Coursera, offered by Duke University. + +Though data science is in the name, the course teaches the core math upon which both data science and data analytics are built. You'll learn about set theory, math notation, probability theory, etc. The expected duration of the course is 15 hours and you can enroll in it for free. + +The completion of this course is essential for you to be ready for the statistical module of Ironhack's bootcamp. +That is the reason why you are asked to submit all the `Practice Exercises` and `Quizes` you will find in the `Data Science Math Skills` course. + +**Watch the lesson videos, read the recommended articles and when you feel ready, complete the practice exercises and quizes for each week. When you are done, take screenshots of all the solved exercises and save them for later submission.** + +Here's the complete list of exercises you need to deliver: + +**WEEK 1** +* Building Blocks for Problem Solving - Practice quiz on Sets (3 questions) +* The infinite World of Real Numbers - Practice quiz on the Number Line, including Inequalities (8 questions) +* That Jagged S Symbol - Practice quiz on Simplification Rules and Sigma Notation (6 questions) +* That Jagged S Symbol - Graded quiz on Sets, Number Line, Inequalities, Simplification, and Sigma Notation (13 questions) + +**WEEK 2** +* Descartes Was Really Smart - Practice quiz on the Cartesian Plane (5 questions) +* Input-Output Machines - Practice quiz on Types of Functions (6 questions) +* Input-Output Machines - Graded quiz on Cartesian Plane and Types of Function (13 questions) + +**WEEK 3** +* This is about that derivative stuff - Practice quiz on Tangent Lines to Functions (2 questions) +* Fast Growth, Slow Growth - Practice quiz on Exponents and Logarithms (12 questions) +* Fast Growth, Slow Growth - Graded quiz on Tangent Lines to Functions, Exponents and Logarithms (13 questions) + +**WEEK 4** +* Basic Probability Definitions - Practice quiz on Probability Concepts (9 questions) +* Problem Solving Methods - Practice quiz on Problem Solving (9 questions) +* Applying Bayes Theorem and the Binomial Theorem - Practice quiz on Bayes Theorem and the Binomial Theorem (9 questions) +* Applying Bayes Theorem and the Binomial Theorem - Probability (basic and Intermediate) Graded Quiz (12 questions)