diff --git a/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb b/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb index 34021448a..2334a5a4b 100644 --- a/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb +++ b/1.-Python/1.-Snail-and-Well/snail-and-well.ipynb @@ -30,10 +30,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "well_height= 125\n", + "daily_distance=30\n", + "nightly_distance=20\n", + "snail_position=0" + ] }, { "cell_type": "markdown", @@ -44,10 +49,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "days=0" + ] }, { "cell_type": "markdown", @@ -58,10 +65,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "while snail_position < well_height:\n", + " snail_position = snail_position + (daily_distance - nightly_distance)\n", + " days = days+1" + ] }, { "cell_type": "markdown", @@ -72,10 +83,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "print(days)" + ] }, { "cell_type": "markdown", @@ -96,10 +117,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "well_height= 125\n", + "nightly_distance=20\n", + "snail_position=0\n", + "days=0\n", + "\n", + "while snail_position < well_height:\n", + " snail_position = snail_position + advance_cm[days] - nightly_distance\n", + " days = days + 1\n", + "\n", + "print(days)" + ] }, { "cell_type": "markdown", @@ -111,10 +152,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "57\n", + "1\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "well_height= 125\n", + "nightly_distance=20\n", + "snail_position=0\n", + "days=0\n", + "distance_per_day = []\n", + "\n", + "while snail_position < well_height:\n", + " snail_position = snail_position + advance_cm[days] - nightly_distance\n", + " distance_per_day.append(advance_cm[days] - nightly_distance)\n", + " days = days + 1\n", + "\n", + "print(max(distance_per_day))\n", + "print(min(distance_per_day))" + ] }, { "cell_type": "markdown", @@ -125,10 +190,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "21.666666666666668\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "well_height= 125\n", + "nightly_distance=20\n", + "snail_position=0\n", + "days=0\n", + "distance_per_day = []\n", + "\n", + "while snail_position < well_height:\n", + " snail_position = snail_position + advance_cm[days] - nightly_distance\n", + " distance_per_day.append(advance_cm[days] - nightly_distance)\n", + " days = days + 1\n", + "\n", + "print(sum(distance_per_day)/len(distance_per_day))" + ] }, { "cell_type": "markdown", @@ -137,6 +224,47 @@ "#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night." ] }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "17.81073334319006\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "well_height= 125\n", + "nightly_distance=20\n", + "snail_position=0\n", + "days=0\n", + "distance_per_day = []\n", + "deviation = 0.0\n", + "\n", + "while snail_position < well_height:\n", + " snail_position = snail_position + advance_cm[days] - nightly_distance\n", + " distance_per_day.append(advance_cm[days] - nightly_distance)\n", + " days = days + 1\n", + " \n", + "#Starting process of standard deviation#\n", + "for i in distance_per_day:\n", + " deviation =deviation + (i - sum(distance_per_day)/len(distance_per_day))**2\n", + "\n", + "print((deviation/len(distance_per_day))**0.5)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -161,7 +289,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb index b4a5f6d7e..459e93b89 100644 --- a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb +++ b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb @@ -49,10 +49,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "spells=0" + ] }, { "cell_type": "markdown", @@ -64,10 +66,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins=0\n", + "saruman_wins=0" + ] }, { "cell_type": "markdown", @@ -78,10 +83,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "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=0\n", + "gandalf_wins=0\n", + "saruman_wins=0\n", + "\n", + "for i in range(0,len(gandalf)):\n", + "\tif gandalf[i] < saruman[i]:\n", + "\t\tsaruman_wins=saruman_wins+1\n", + "\telse:\n", + "\t\tgandalf_wins=gandalf_wins+1" + ] }, { "cell_type": "markdown", @@ -93,10 +110,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf wins\n" + ] + } + ], + "source": [ + "if gandalf_wins < saruman_wins:\n", + "\tprint(\"Saruman wins\")\n", + "elif gandalf_wins == saruman_wins:\n", + "\tprint(\"Tie\")\n", + "else:\n", + "\tprint(\"Gandalf wins\")" + ] }, { "cell_type": "markdown", @@ -128,10 +160,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], - "source": [] + "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\n" + ] }, { "cell_type": "markdown", @@ -142,10 +187,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins=0\n", + "saruman_wins=0" + ] }, { "cell_type": "markdown", @@ -156,10 +204,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_power=[\"\"]\n", + "saruman_power=[\"\"]" + ] }, { "cell_type": "markdown", @@ -171,10 +222,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tie\n" + ] + } + ], + "source": [ + "for i in range(0,len(gandalf)):\n", + "\tif (len(gandalf_power)<3 & len(saruman_power)<3):\n", + "\t\tif POWER(gandalf[i]) < POWER(saruman[i]):\n", + "\t\t\tsaruman_wins=saruman_wins+1\n", + "\t\t\tsaruman_power.append(saruman(i))\n", + "\t\t\tgandalf_power.clear()\n", + "\t\telif POWER(gandalf[i]) > POWER(saruman[i]):\n", + "\t\t\tgandalf_wins=gandalf_wins+1\n", + "\t\t\tgandalf_power.append(gandalf(i))\n", + "\t\t\tsaruman_power.clear()\n", + "\n", + "if saruman_wins == 3:\n", + "\tprint (\"Saruman wins\")\n", + "elif gandalf_wins == 3:\n", + "\tprint (\"Gandalf wins\")\n", + "else:\n", + " print(\"Tie\")" + ] }, { "cell_type": "markdown", @@ -185,10 +262,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "ename": "TypeError", + "evalue": "'dict' object is not callable", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\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 10\u001b[0m \u001b[0msaruman_power\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclear\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 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mPOWER\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msaruman\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[0m", + "\u001b[1;31mTypeError\u001b[0m: 'dict' object is not callable" + ] + } + ], + "source": [ + "for i in range(0,len(gandalf)):\n", + "\tif (len(gandalf_power)<3 & len(saruman_power)<3):\n", + "\t\tif POWER(gandalf[i]) < POWER(saruman[i]):\n", + "\t\t\tsaruman_wins=saruman_wins+1\n", + "\t\t\tsaruman_power.append(saruman(i))\n", + "\t\t\tgandalf_power.clear()\n", + "\t\telif POWER(gandalf[i]) > POWER(saruman[i]):\n", + "\t\t\tgandalf_wins=gandalf_wins+1\n", + "\t\t\tgandalf_power.append(gandalf(i))\n", + "\t\t\tsaruman_power.clear()\n", + "\n" + ] }, { "cell_type": "markdown", @@ -221,7 +322,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/1.-Python/3.-Bus/bus.ipynb b/1.-Python/3.-Bus/bus.ipynb index 31f09b8fd..f41d1087f 100644 --- a/1.-Python/3.-Bus/bus.ipynb +++ b/1.-Python/3.-Bus/bus.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -52,10 +52,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9\n" + ] + } + ], + "source": [ + "print(len(stops))" + ] }, { "cell_type": "markdown", @@ -67,10 +77,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "13\n", + "11\n", + "10\n", + "14\n", + "10\n", + "7\n", + "5\n", + "4\n", + "4\n" + ] + } + ], + "source": [ + "\n", + "for passengers in stops:\n", + " passenger_total = passenger_total + passengers[0] - passengers[1]\n", + "print(passenger_total)\n" + ] }, { "cell_type": "markdown", @@ -81,10 +113,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "14\n" + ] + } + ], + "source": [ + "list_passenger = []\n", + "for passengers in stops:\n", + " passenger_total = passenger_total + passengers[0] - passengers[1]\n", + " list_passenger.append(passenger_total)\n", + "\n", + "print(max(list_passenger)) " + ] }, { "cell_type": "markdown", @@ -93,6 +140,33 @@ "#### 4. Calculate the average occupation. And the standard deviation." ] }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average: 9.333333333333334\n", + "standard deviation: 3.197221015541813\n" + ] + } + ], + "source": [ + "import numpy\n", + "passenger_total = 0\n", + "list_passenger = []\n", + "for passengers in stops:\n", + " passenger_total = passenger_total + passengers[0] - passengers[1]\n", + " list_passenger.append(passenger_total)\n", + "\n", + "print(\"average:\" , sum(list_passenger)/len(list_passenger))\n", + "print( \"standard deviation:\" , numpy.std(list_passenger))\n", + " " + ] + }, { "cell_type": "code", "execution_count": null, @@ -117,9 +191,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/1.-Python/4.-Robin-Hood/robin-hood.ipynb b/1.-Python/4.-Robin-Hood/robin-hood.ipynb index 01de29d3b..28e9df61b 100644 --- a/1.-Python/4.-Robin-Hood/robin-hood.ipynb +++ b/1.-Python/4.-Robin-Hood/robin-hood.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -55,10 +55,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "coordinates where arrow hits another arrow: {(-3, 2), (4, 5), (5, 7), (2, 2)}\n" + ] + } + ], + "source": [ + "counter = 0;\n", + "set_arrows = []\n", + "for point in points:\n", + " if points.count(point) >= 2:\n", + " set_arrows.append(point)\n", + "\n", + "print( \"coordinates where arrow hits another arrow: \", set(set_arrows))\n" + ] }, { "cell_type": "markdown", @@ -70,10 +86,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Count of arrow that have fallen in a cuadrant: 2\n" + ] + } + ], + "source": [ + "counter = 0;\n", + "set_arrows = []\n", + "for point in points:\n", + " if point[0] == 0 or point[1] == 0:\n", + " set_arrows.append(point)\n", + "\n", + "print( \" Count of arrow that have fallen in a cuadrant: \", len(set_arrows))" + ] }, { "cell_type": "markdown", @@ -88,10 +120,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "minimum distance: 2.0\n" + ] + } + ], + "source": [ + "import math\n", + "\n", + "def calc_distance(p1, p2):\n", + " return sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) \n", + "\n", + "minimum_distance = -1\n", + "for point in points:\n", + " if minimum_distance == -1 or minimum_distance > calc_distance(point,[0,0]):\n", + " minimum_distance = calc_distance(point,[0,0])\n", + "\n", + "print(\"minimum distance: \",minimum_distance) \n", + "\n" + ] }, { "cell_type": "markdown", @@ -125,9 +178,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/1.-Python/5.-Temperature-Processor/temperature.ipynb b/1.-Python/5.-Temperature-Processor/temperature.ipynb index 4b597aa20..ee4fcdb10 100644 --- a/1.-Python/5.-Temperature-Processor/temperature.ipynb +++ b/1.-Python/5.-Temperature-Processor/temperature.ipynb @@ -28,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -53,10 +53,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "minimum_temp = min(temperatures_C)\n", + "\n", + "print(minimum_temp)" + ] }, { "cell_type": "markdown", @@ -67,10 +79,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "90\n" + ] + } + ], + "source": [ + "maximum_temp = max(temperatures_C)\n", + "print(maximum_temp)" + ] }, { "cell_type": "markdown", @@ -81,10 +104,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[90, 83, 81, 80, 80, 79, 76, 70, 66, 65, 64, 62, 61, 60, 59, 53, 53, 50, 49, 48, 45, 39, 33, 0]\n", + "8\n", + "[90, 83, 81, 80, 80, 79, 76, 70]\n" + ] + } + ], + "source": [ + "high_temp = temperatures_C.copy()\n", + "high_temp.sort()\n", + "high_temp.reverse()\n", + "ind = 0\n", + "\n", + "while high_temp[ind] >= 70:\n", + " ind = ind +1\n", + " \n", + "del high_temp[ind:]\n", + "\n", + "print(high_temp)\n" + ] }, { "cell_type": "markdown", @@ -95,10 +140,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.25\n" + ] + } + ], + "source": [ + "avg_temp = sum(temperatures_C)/len(temperatures_C)\n", + "print(avg_temp)" + ] }, { "cell_type": "markdown", @@ -109,10 +165,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[33, 66, 65, 62, 59, 60, 62, 64, 70, 76, 80, 81, 80, 83, 90, 79, 61, 53, 50, 49, 53, 48, 45, 39]\n" + ] + } + ], + "source": [ + "#doing some forcast formula like exponential smoothing or linear regretion (will use just a average between the closest values of 3 am)\n", + "\n", + "temperatures_C[3] = int((temperatures_C[2] + temperatures_C[4])/2)\n", + "\n", + "print(temperatures_C)\n", + "\n" + ] }, { "cell_type": "markdown", @@ -128,10 +199,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[91, 150, 149, 143, 138, 140, 143, 147, 158, 168, 176, 177, 176, 181, 194, 174, 141, 127, 122, 120, 127, 118, 113, 102]\n" + ] + } + ], + "source": [ + "temperatures_F = []\n", + "for temp in temperatures_C:\n", + " temperatures_F.append(int(1.8 * temp + 32))\n", + "\n", + "temperatures_C = temperatures_F\n", + "print(temperatures_C)\n" + ] }, { "cell_type": "markdown", @@ -150,10 +236,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cooling system need to be changed\n" + ] + } + ], + "source": [ + "high_temp = temperatures_C.copy()\n", + "high_temp.sort()\n", + "high_temp.reverse()\n", + "medium_temp = 0\n", + "evaluated = 0\n", + "\n", + "for value in high_temp:\n", + " if value >= 80:\n", + " print (\"Cooling system need to be changed\")\n", + " evaluated = 1\n", + " break\n", + " if value < 80 and value >= 70:\n", + " medium_temp = medium_temp + 1\n", + " if medium_temp == 4:\n", + " evaluated = 1\n", + " print (\"Cooling system need to be changed\")\n", + " break\n", + "if evaluated == 0:\n", + " if sum(temperatures_C)/len(temperatures_C) > 65:\n", + " print(\"Cooling system need to be changed\")\n", + " else:\n", + " print(\"Cooling system do not need to be changed\")\n" + ] }, { "cell_type": "markdown", @@ -254,9 +371,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" index 9e551dfd4..a52a7ad68 100644 --- "a/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" +++ "b/1.-Python/6.-Rock\342\200\223Paper\342\200\223Scissors/rock-paper-scissors.ipynb" @@ -32,10 +32,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import random" + ] }, { "cell_type": "markdown", @@ -46,10 +48,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gestures = [\"paper\",\"rock\",\"scissors\"]" + ] }, { "cell_type": "markdown", @@ -61,10 +65,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "n_rounds = 7" + ] }, { "cell_type": "markdown", @@ -79,7 +85,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "rounds_to_win = 4" + ] }, { "cell_type": "markdown", @@ -90,10 +98,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "cpu_score = 0\n", + "player_score = 0" + ] }, { "cell_type": "markdown", @@ -105,10 +116,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def random_play (p_gestures):\n", + " return random.choice(p_gestures)\n" + ] }, { "cell_type": "markdown", @@ -120,10 +134,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def users_gesture():\n", + " user_gest = \"\"\n", + " while gestures.count(user_gest) == 0:\n", + " user_gest = input(\"escribe que eliges entre rock, scissors, paper:\" )\n", + " return user_gest\n" + ] }, { "cell_type": "markdown", @@ -135,10 +155,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def winner(p_program, p_user):\n", + " win = -1\n", + " if p_program == p_user:\n", + " win = 0\n", + " elif (p_program == \"rock\" and p_user ==\"scissors\") or (p_program == \"scissors\" and p_user ==\"paper\") or (p_program == \"paper\" and p_user ==\"rock\"):\n", + " win = 1\n", + " else:\n", + " win = 2\n", + " return win; " + ] }, { "cell_type": "markdown", @@ -150,10 +180,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def print_winner(winner):\n", + " if winner == 1:\n", + " print(\"computadora gano\");\n", + " elif winner == 2:\n", + " print(\"usuario gano\");\n", + " else:\n", + " print(\"empate\");" + ] }, { "cell_type": "markdown", @@ -168,10 +206,149 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------ 1 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: paper\n", + "computadora gano\n", + "------------------------------ 2 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: paper\n", + "computadora gano\n", + "------------------------------ 3 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: scissors\n", + "usuario gano\n", + "------------------------------ 4 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: scissors\n", + "usuario gano\n", + "------------------------------ 5 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: paper\n", + "computadora gano\n", + "------------------------------ 6 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: rock\n", + "empate\n", + "------------------------------ 7 round ------------------------------\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "escribe que eliges entre rock, scissors, paper: rock\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computadora eligió: paper\n", + "computadora gano\n" + ] + } + ], + "source": [ + "random_value = \"\"\n", + "win = \"\"\n", + "cpu_score = 0\n", + "player_score = 0\n", + "\n", + "for i in range(0,n_rounds):\n", + " print(\"-\"*30,\" \",i+1,\"round \",\"-\"*30)\n", + " random_value = random_play(gestures)\n", + " win = winner( random_value , users_gesture() )\n", + " print(\"Computadora eligió: \", random_value)\n", + " if win == 1:\n", + " cpu_score = cpu_score + 1\n", + " print_winner(1)\n", + " elif win == 2:\n", + " player_score = player_score + 1\n", + " print_winner(2)\n", + " else:\n", + " print_winner(0)\n", + " \n" + ] }, { "cell_type": "markdown", @@ -183,10 +360,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "computadora gano\n" + ] + } + ], + "source": [ + "if cpu_score == 4:\n", + " print_winner(1)\n", + "elif player_score == 4:\n", + " print_winner(2)\n", + "else:\n", + " print_winner(3)\n", + "\n", + "cpu_score = 0\n", + "player_score = 0" + ] }, { "cell_type": "markdown", @@ -226,9 +421,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/2.-Statistics/week1-1.PNG b/2.-Statistics/week1-1.PNG new file mode 100644 index 000000000..3ed2818a1 Binary files /dev/null and b/2.-Statistics/week1-1.PNG differ diff --git a/2.-Statistics/week1-2.PNG b/2.-Statistics/week1-2.PNG new file mode 100644 index 000000000..bf957f15b Binary files /dev/null and b/2.-Statistics/week1-2.PNG differ diff --git a/2.-Statistics/week1-3.PNG b/2.-Statistics/week1-3.PNG new file mode 100644 index 000000000..3ca3ac61a Binary files /dev/null and b/2.-Statistics/week1-3.PNG differ diff --git a/2.-Statistics/week1-4.PNG b/2.-Statistics/week1-4.PNG new file mode 100644 index 000000000..7c94e600a Binary files /dev/null and b/2.-Statistics/week1-4.PNG differ diff --git a/2.-Statistics/week2-1.PNG b/2.-Statistics/week2-1.PNG new file mode 100644 index 000000000..953b7bdda Binary files /dev/null and b/2.-Statistics/week2-1.PNG differ diff --git a/2.-Statistics/week2-2.PNG b/2.-Statistics/week2-2.PNG new file mode 100644 index 000000000..afd0ea373 Binary files /dev/null and b/2.-Statistics/week2-2.PNG differ diff --git a/2.-Statistics/week2-3.PNG b/2.-Statistics/week2-3.PNG new file mode 100644 index 000000000..58d37394e Binary files /dev/null and b/2.-Statistics/week2-3.PNG differ diff --git a/2.-Statistics/week3-1.PNG b/2.-Statistics/week3-1.PNG new file mode 100644 index 000000000..ca2a441bc Binary files /dev/null and b/2.-Statistics/week3-1.PNG differ diff --git a/2.-Statistics/week3-2.PNG b/2.-Statistics/week3-2.PNG new file mode 100644 index 000000000..513b27360 Binary files /dev/null and b/2.-Statistics/week3-2.PNG differ diff --git a/2.-Statistics/week3-3.PNG b/2.-Statistics/week3-3.PNG new file mode 100644 index 000000000..7e459a064 Binary files /dev/null and b/2.-Statistics/week3-3.PNG differ diff --git a/2.-Statistics/week4-1.PNG b/2.-Statistics/week4-1.PNG new file mode 100644 index 000000000..5fb2b37a3 Binary files /dev/null and b/2.-Statistics/week4-1.PNG differ diff --git a/2.-Statistics/week4-2.PNG b/2.-Statistics/week4-2.PNG new file mode 100644 index 000000000..11df6b6b2 Binary files /dev/null and b/2.-Statistics/week4-2.PNG differ diff --git a/2.-Statistics/week4-3.PNG b/2.-Statistics/week4-3.PNG new file mode 100644 index 000000000..bdf38ab35 Binary files /dev/null and b/2.-Statistics/week4-3.PNG differ diff --git a/2.-Statistics/week4-4.PNG b/2.-Statistics/week4-4.PNG new file mode 100644 index 000000000..901dfabfc Binary files /dev/null and b/2.-Statistics/week4-4.PNG differ