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 3402144..a37ca64 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,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "while snail_position <= well_height :\n", + " snail_position += daily_distance\n", + " if snail_position <= well_height :\n", + " snail_position += nightly_distance\n", + " days = days + 1" + ] }, { "cell_type": "markdown", @@ -72,10 +85,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Days = 11\n" + ] + } + ], + "source": [ + "print(\"Days =\", days)" + ] }, { "cell_type": "markdown", @@ -96,10 +119,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Days = 6\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "snail_position = 0\n", + "days = 0\n", + "\n", + "while snail_position <= well_height :\n", + " snail_position += advance_cm[days]\n", + " if snail_position <= well_height :\n", + " snail_position += nightly_distance\n", + " days = days + 1\n", + "\n", + "print(\"Days =\", days)" + ] }, { "cell_type": "markdown", @@ -111,10 +154,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max displacement = 57\n", + "Min displacement = 1\n" + ] + } + ], + "source": [ + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "snail_position = 0\n", + "days = 0\n", + "displacement = []\n", + "\n", + "while snail_position <= well_height :\n", + " snail_position += advance_cm[days] + nightly_distance\n", + " displacement.append(advance_cm[days] + nightly_distance)\n", + " days = days + 1\n", + "\n", + "print(\"Max displacement =\", max(displacement))\n", + "print(\"Min displacement =\", min(displacement))" + ] }, { "cell_type": "markdown", @@ -125,18 +190,71 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average displacement = 21.666666666666668\n", + "Average displacement = 21.666666666666668\n" + ] + } + ], + "source": [ + "import numpy\n", + "average = numpy.mean(displacement)\n", + "print(\"Average displacement =\", average)\n", + "\n", + "import statistics\n", + "average2 = statistics.mean(displacement)\n", + "print(\"Average displacement =\", average2)" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night." + "4. What is the standard deviation of its displacement? Take into account the snail slides at night." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Standard deviation = 17.81073334319006\n", + "Standard deviation = 17.81073334319006\n" + ] + } + ], + "source": [ + "std_dev = numpy.std(displacement)\n", + "print(\"Standard deviation =\", std_dev)\n", + "\n", + "std_dev2 = statistics.pstdev(displacement)\n", + "print(\"Standard deviation =\", std_dev2)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -161,7 +279,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "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 b4a5f6d..e3711fa 100644 --- a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb +++ b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb @@ -49,10 +49,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "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" + ] }, { "cell_type": "markdown", @@ -64,10 +68,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0" + ] }, { "cell_type": "markdown", @@ -78,10 +85,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "while spells < len(gandalf) :\n", + " if gandalf[spells] > saruman[spells] :\n", + " gandalf_wins += 1\n", + " else :\n", + " saruman_wins += 1\n", + " spells += 1" + ] }, { "cell_type": "markdown", @@ -93,10 +107,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf wins!\n" + ] + } + ], + "source": [ + "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", @@ -128,10 +157,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, "outputs": [], - "source": [] + "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','Magic arrow','Lightning bolt','Fireball','Fireball','Fireball']\n", + "saruman = ['Contagion','Contagion','Black Tentacles','Fireball','Black Tentacles','Lightning bolt','Magic arrow','Contagion','Magic arrow','Magic arrow']\n", + "spells = 0" + ] }, { "cell_type": "markdown", @@ -142,10 +176,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0" + ] }, { "cell_type": "markdown", @@ -156,10 +193,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_power = []\n", + "saruman_power = []" + ] }, { "cell_type": "markdown", @@ -171,10 +211,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf wins!\n" + ] + } + ], + "source": [ + "gandalf_wins_row = 0\n", + "saruman_wins_row = 0\n", + "\n", + "while spells < len(gandalf) :\n", + " gandalf_power.append(POWER[gandalf[spells]])\n", + " saruman_power.append(POWER[saruman[spells]])\n", + "\n", + " if gandalf_power[spells] > saruman_power[spells] :\n", + " gandalf_wins += 1\n", + " saruman_wins = 0\n", + " if gandalf_wins % 3 == 0 :\n", + " gandalf_wins_row += 1\n", + " elif gandalf_power[spells] < saruman_power[spells] :\n", + " saruman_wins += 1\n", + " gandalf_wins = 0\n", + " if saruman_wins % 3 == 0 :\n", + " saruman_wins_row += 1\n", + " spells += 1\n", + "\n", + "if gandalf_wins_row > saruman_wins_row :\n", + " print(\"Gandalf wins!\")\n", + "elif gandalf_wins_row < saruman_wins_row :\n", + " print(\"Saruman wins!\")\n", + "else :\n", + " print(\"Tie!\")" + ] }, { "cell_type": "markdown", @@ -185,10 +259,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 59, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average Gandalf = 39.0\n", + "Average Saruman = 30.5\n" + ] + } + ], + "source": [ + "import numpy\n", + "print(\"Average Gandalf =\", numpy.mean(gandalf_power))\n", + "print(\"Average Saruman =\", numpy.mean(saruman_power))" + ] }, { "cell_type": "markdown", @@ -197,6 +284,25 @@ "#### 6. Find the standard deviation of the spell power of Gandalf and Saruman. " ] }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Standard deviation Gandalf = 15.132745950421556\n", + "Standard deviation Saruman = 15.56438241627338\n" + ] + } + ], + "source": [ + "print(\"Standard deviation Gandalf =\", numpy.std(gandalf_power))\n", + "print(\"Standard deviation Saruman =\", numpy.std(saruman_power))" + ] + }, { "cell_type": "code", "execution_count": null, @@ -221,7 +327,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/1.-Python/3.-Bus/bus.ipynb b/1.-Python/3.-Bus/bus.ipynb index 31f09b8..4eabe6d 100755 --- 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": 1, "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": [ + "Number of stops = 9\n" + ] + } + ], + "source": [ + "print(\"Number of stops =\", len(stops))" + ] }, { "cell_type": "markdown", @@ -67,10 +77,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Passengers at each stop = [10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "passengers = [0]\n", + "\n", + "for i in range(len(stops)) :\n", + " passengers.append(passengers[i] + stops[i][0] - stops[i][1])\n", + "passengers.remove(passengers[0])\n", + "\n", + "print(\"Passengers at each stop =\", passengers)" + ] }, { "cell_type": "markdown", @@ -81,10 +107,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max occupation = 14\n" + ] + } + ], + "source": [ + "print(\"Max occupation =\", max(passengers))" + ] }, { "cell_type": "markdown", @@ -93,6 +129,26 @@ "#### 4. Calculate the average occupation. And the standard deviation." ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average occupation 9.333333333333334\n", + "Standard deviation = 3.197221015541813\n" + ] + } + ], + "source": [ + "import numpy\n", + "print(\"Average occupation\", numpy.mean(passengers))\n", + "print(\"Standard deviation =\", numpy.std(passengers))" + ] + }, { "cell_type": "code", "execution_count": null, @@ -117,7 +173,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/1.-Python/4.-Robin-Hood/robin-hood.ipynb b/1.-Python/4.-Robin-Hood/robin-hood.ipynb index 01de29d..f049b6f 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": 23, "metadata": {}, "outputs": [], "source": [ @@ -55,10 +55,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{(4, 5), (5, 7), (-3, 2), (2, 2)}\n" + ] + } + ], + "source": [ + "arrow_hits_arrow = []\n", + "\n", + "for i in points :\n", + " if points.count(i) >= 2 :\n", + " arrow_hits_arrow.append(i)\n", + "\n", + "print(set(arrow_hits_arrow))" + ] }, { "cell_type": "markdown", @@ -70,10 +86,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Arrow in Q1 = 10\n", + "Arrow in Q2 = 6\n", + "Arrow in Q3 = 2\n", + "Arrow in Q4 = 2\n" + ] + } + ], + "source": [ + "Q1 = 0\n", + "Q2 = 0\n", + "Q3 = 0\n", + "Q4 = 0\n", + "\n", + "for x,y in points :\n", + " if x > 0 and y > 0 :\n", + " Q1 += 1\n", + " if x < 0 and y > 0 :\n", + " Q2 += 1\n", + " if x < 0 and y < 0 :\n", + " Q3 += 1\n", + " if x > 0 and y < 0 :\n", + " Q4 += 1\n", + "\n", + "print(\"Arrow in Q1 =\", Q1)\n", + "print(\"Arrow in Q2 =\", Q2)\n", + "print(\"Arrow in Q3 =\", Q3)\n", + "print(\"Arrow in Q4 =\", Q4)" + ] }, { "cell_type": "markdown", @@ -88,10 +135,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Point closest to the center: (0, 2)\n", + "Point closest to the center: (0, -2)\n", + "Min distance to the center = 2.0\n" + ] + } + ], + "source": [ + "def distance(x,y) :\n", + " return (x**2 + y**2)**0.5\n", + "\n", + "distances = []\n", + "\n", + "for x,y in points :\n", + " distances.append(distance(x,y))\n", + "\n", + "for x,y in points :\n", + " if distance(x,y) == min(distances) :\n", + " print(\"Point closest to the center:\", (x,y))\n", + " \n", + "print(\"Min distance to the center =\", min(distances))" + ] }, { "cell_type": "markdown", @@ -101,6 +172,29 @@ "**Hint**: Use the function created in step 3. " ] }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Arrows out of target = 2\n" + ] + } + ], + "source": [ + "count = 0\n", + "\n", + "for i in distances :\n", + " if i > 9 :\n", + " count += 1\n", + "\n", + "print(\"Arrows out of target =\", count)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -125,7 +219,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/1.-Python/5.-Temperature-Processor/temperature.ipynb b/1.-Python/5.-Temperature-Processor/temperature.ipynb index 4b597aa..49e448f 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": 71, "metadata": {}, "outputs": [], "source": [ @@ -53,10 +53,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "T_min = min(temperatures_C)\n", + "print(T_min)" + ] }, { "cell_type": "markdown", @@ -67,10 +78,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "90\n" + ] + } + ], + "source": [ + "T_max = max(temperatures_C)\n", + "print(T_max)" + ] }, { "cell_type": "markdown", @@ -81,10 +103,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[70, 76, 80, 81, 80, 83, 90, 79]\n" + ] + } + ], + "source": [ + "T_greater_or_equal_70 = []\n", + "\n", + "for i in temperatures_C :\n", + " if i >= 70 :\n", + " T_greater_or_equal_70.append(i)\n", + "\n", + "print(T_greater_or_equal_70)" + ] }, { "cell_type": "markdown", @@ -95,10 +133,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.25\n" + ] + } + ], + "source": [ + "import numpy\n", + "T_average = numpy.mean(temperatures_C)\n", + "print(T_average)" + ] }, { "cell_type": "markdown", @@ -109,10 +159,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "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": [ + "import numpy\n", + "def T_estimate(index) :\n", + " return numpy.mean([temperatures_C[index-1] , temperatures_C[index+1]])\n", + "\n", + "index = 3\n", + "temperatures_C[index] = int(T_estimate(index))\n", + "print(temperatures_C)" + ] }, { "cell_type": "markdown", @@ -128,10 +194,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Temperatures in Fahrenheit = [91, 151, 149, 144, 138, 140, 144, 147, 158, 169, 176, 178, 176, 181, 194, 174, 142, 127, 122, 120, 127, 118, 113, 102]\n" + ] + } + ], + "source": [ + "temperatures_F = []\n", + "\n", + "for i in temperatures_C :\n", + " temperatures_F.append(round(i * 1.8 + 32))\n", + "\n", + "print(\"Temperatures in Fahrenheit =\", temperatures_F)" + ] }, { "cell_type": "markdown", @@ -150,10 +231,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The cooling system needs to be changed!\n" + ] + } + ], + "source": [ + "T_average_new = numpy.mean(temperatures_C)\n", + "\n", + "if len(T_greater_or_equal_70) > 4 or T_max > 80 or T_average_new > 65 :\n", + " print(\"The cooling system needs to be changed!\")\n", + "else :\n", + " print(\"The cooling sytem doesn't need to be changed.\")" + ] }, { "cell_type": "markdown", @@ -175,10 +271,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[76, 80, 81, 80, 83, 90, 79]\n" + ] + } + ], + "source": [ + "T_greater_70 = []\n", + "\n", + "for i in temperatures_C :\n", + " if i > 70 :\n", + " T_greater_70.append(i)\n", + " \n", + "print(T_greater_70)" + ] }, { "cell_type": "markdown", @@ -189,10 +301,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 113, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 10, 11, 12, 13, 14, 15]\n", + "yes\n" + ] + } + ], + "source": [ + "indexes = []\n", + "for i in range(len(temperatures_C)) :\n", + " if temperatures_C[i] > 70 :\n", + " T_greater_70.append(temperatures_C[i])\n", + " indexes.append(i)\n", + "print(indexes)\n", + "\n", + "count = 0\n", + "for i in range(0,len(indexes)-1) :\n", + " if indexes[i] - indexes[i+1] == -1 :\n", + " count += 1\n", + " if count >= 3 :\n", + " consecutive = \"yes\"\n", + " else :\n", + " count = 0\n", + "print(consecutive)" + ] }, { "cell_type": "markdown", @@ -204,10 +342,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The cooling system needs to be changed!\n" + ] + } + ], + "source": [ + "if count > 4 or T_max > 80 or T_average_new > 65 :\n", + " print(\"The cooling system needs to be changed!\")\n", + "else :\n", + " print(\"The cooling sytem doesn't need to be changed.\")" + ] }, { "cell_type": "markdown", @@ -218,10 +369,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average temperature in C = 62.8\n", + "Average temperature in F = 145.0\n", + "The relation between both averages is the same: F = 1.8 * C + 32\n" + ] + } + ], + "source": [ + "T_average_F = numpy.mean(temperatures_F)\n", + "print(\"Average temperature in C =\", round(T_average_new,1))\n", + "print(\"Average temperature in F =\", round(T_average_F,1))\n", + "print(\"The relation between both averages is the same: F = 1.8 * C + 32\")" + ] }, { "cell_type": "markdown", @@ -230,6 +396,34 @@ "#### 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": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Standard deviation in C = 14.6\n", + "Standard deviation in F = 26.4\n", + "The relation between both standard deviations is now only: F = 1.8 * C, because the 32 is nullified during the calculation\n" + ] + } + ], + "source": [ + "print(\"Standard deviation in C =\", round(numpy.std(temperatures_C),1))\n", + "print(\"Standard deviation in F =\", round(numpy.std(temperatures_F),1))\n", + "print(\"The relation between both standard deviations is now only: F = 1.8 * C, because the 32 is nullified during the calculation\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -254,7 +448,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "nbformat": 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 9e551df..942fb54 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": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "from random import choice" + ] }, { "cell_type": "markdown", @@ -46,10 +48,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gestures = ['rock', 'paper', 'scissors']" + ] }, { "cell_type": "markdown", @@ -61,10 +65,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "n_rounds = 9" + ] }, { "cell_type": "markdown", @@ -76,10 +82,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "rounds_to_win = n_rounds / 3" + ] }, { "cell_type": "markdown", @@ -90,10 +98,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "cpu_score = 0\n", + "player_score = 0" + ] }, { "cell_type": "markdown", @@ -105,10 +116,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "scissors\n" + ] + } + ], + "source": [ + "def cpu_plays() :\n", + " cpu_plays.i = choice(gestures)\n", + " return cpu_plays.i\n", + "\n", + "print(cpu_plays())" + ] }, { "cell_type": "markdown", @@ -120,10 +145,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your play (you must choose between rock, paper or scissors)? paper\n", + "paper\n" + ] + } + ], + "source": [ + "def player_plays() :\n", + " player_plays.i = \"\"\n", + " while player_plays.i not in gestures :\n", + " player_plays.i = input(\"Your play (you must choose between rock, paper or scissors)? \")\n", + " if player_plays.i == \"rock\" :\n", + " return player_plays.i\n", + " elif player_plays.i == \"paper\" :\n", + " return player_plays.i\n", + " elif player_plays.i == \"scissors\" :\n", + " return player_plays.i\n", + "\n", + "print(player_plays())" + ] }, { "cell_type": "markdown", @@ -135,10 +182,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your play (you must choose between rock, paper or scissors)? paper\n", + "2\n" + ] + } + ], + "source": [ + "def round_winner() :\n", + " cpu_plays()\n", + " player_plays()\n", + " if cpu_plays.i == player_plays.i :\n", + " return 0\n", + " elif (cpu_plays.i == \"rock\" and player_plays.i == \"scissors\") or (cpu_plays.i == \"scissors\" and player_plays.i == \"paper\") or (cpu_plays.i == \"paper\" and player_plays.i == \"rock\") :\n", + " return 1\n", + " else :\n", + " return 2\n", + "\n", + "print(round_winner())" + ] }, { "cell_type": "markdown", @@ -150,10 +218,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your play (you must choose between rock, paper or scissors)? paper\n", + "player plays: paper\n", + "cpu plays: paper\n", + "tie\n", + "player score = 0\n", + "cpu score = 0\n", + "\n" + ] + } + ], + "source": [ + "def results() :\n", + " result = round_winner()\n", + " global cpu_score\n", + " global player_score\n", + " print(\"player plays:\", player_plays.i)\n", + " print(\"cpu plays:\", cpu_plays.i)\n", + " if result == 0 :\n", + " print(\"tie\")\n", + " if result == 1 :\n", + " cpu_score += 1\n", + " print(\"cpu wins\")\n", + " if result == 2 :\n", + " player_score += 1\n", + " print(\"player wins\")\n", + " print(\"player score =\", player_score)\n", + " print(\"cpu score =\", cpu_score)\n", + " print(\"\")\n", + "\n", + "results()" + ] }, { "cell_type": "markdown", @@ -168,25 +270,115 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your play (you must choose between rock, paper or scissors)? rock\n", + "player plays: rock\n", + "cpu plays: rock\n", + "tie\n", + "player score = 0\n", + "cpu score = 0\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? rock\n", + "player plays: rock\n", + "cpu plays: rock\n", + "tie\n", + "player score = 0\n", + "cpu score = 0\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? rock\n", + "player plays: rock\n", + "cpu plays: rock\n", + "tie\n", + "player score = 0\n", + "cpu score = 0\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? rock\n", + "player plays: rock\n", + "cpu plays: rock\n", + "tie\n", + "player score = 0\n", + "cpu score = 0\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? rock\n", + "player plays: rock\n", + "cpu plays: paper\n", + "cpu wins\n", + "player score = 0\n", + "cpu score = 1\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? rock\n", + "player plays: rock\n", + "cpu plays: scissors\n", + "player wins\n", + "player score = 1\n", + "cpu score = 1\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? paper\n", + "player plays: paper\n", + "cpu plays: paper\n", + "tie\n", + "player score = 1\n", + "cpu score = 1\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? scissors\n", + "player plays: scissors\n", + "cpu plays: paper\n", + "player wins\n", + "player score = 2\n", + "cpu score = 1\n", + "\n", + "Your play (you must choose between rock, paper or scissors)? paper\n", + "player plays: paper\n", + "cpu plays: paper\n", + "tie\n", + "player score = 2\n", + "cpu score = 1\n", + "\n" + ] + } + ], + "source": [ + "rounds = 1\n", + "while player_score < rounds_to_win and cpu_score < rounds_to_win and rounds <= n_rounds :\n", + " results()\n", + " rounds += 1" + ] }, { - "cell_type": "markdown", + "cell_type": "raw", "metadata": {}, "source": [ - "#### 11. Print the winner of the game based on who won more rounds.\n", + "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, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Player wins!\n" + ] + } + ], + "source": [ + "if player_score > cpu_score :\n", + " print(\"Player wins!\")\n", + "elif cpu_score > player_score :\n", + " print(\"Cpu wins!\")\n", + "else :\n", + " print(\"Tie\")" + ] }, { "cell_type": "markdown", @@ -202,6 +394,142 @@ "**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": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of rounds to play (it must be an odd number)? bla\n", + "Number of rounds to play (it must be an odd number)? 10\n", + "Number of rounds to play (it must be an odd number)? 7\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? rock\n", + "player plays: rock\n", + "cpu plays: rock\n", + "tie\n", + "player score = 0\n", + "cpu score = 0\n", + "\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? spock\n", + "player plays: spock\n", + "cpu plays: scissors\n", + "player wins\n", + "player score = 1\n", + "cpu score = 0\n", + "\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? paper\n", + "player plays: paper\n", + "cpu plays: scissors\n", + "cpu wins\n", + "player score = 1\n", + "cpu score = 1\n", + "\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? lizard\n", + "player plays: lizard\n", + "cpu plays: spock\n", + "player wins\n", + "player score = 2\n", + "cpu score = 1\n", + "\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? paper\n", + "player plays: paper\n", + "cpu plays: lizard\n", + "cpu wins\n", + "player score = 2\n", + "cpu score = 2\n", + "\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? spock\n", + "player plays: spock\n", + "cpu plays: spock\n", + "tie\n", + "player score = 2\n", + "cpu score = 2\n", + "\n", + "Your play (you must choose between rock, paper, scissors, lizard or spock)? paper\n", + "player plays: paper\n", + "cpu plays: scissors\n", + "cpu wins\n", + "player score = 2\n", + "cpu score = 3\n", + "\n", + "Cpu wins!\n" + ] + } + ], + "source": [ + "gestures_bonus = ['rock', 'paper', 'scissors', 'lizard', 'spock']\n", + "cpu_score_bonus = 0\n", + "player_score_bonus = 0\n", + "\n", + "def cpu_plays_bonus() :\n", + " cpu_plays_bonus.i = choice(gestures_bonus)\n", + " return cpu_plays_bonus.i\n", + "\n", + "def player_plays_bonus() :\n", + " player_plays_bonus.i = \"\"\n", + " while player_plays_bonus.i not in gestures_bonus :\n", + " player_plays_bonus.i = input(\"Your play (you must choose between rock, paper, scissors, lizard or spock)? \")\n", + " if player_plays_bonus.i == \"rock\" :\n", + " return player_plays_bonus.i\n", + " elif player_plays_bonus.i == \"paper\" :\n", + " return player_plays_bonus.i\n", + " elif player_plays_bonus.i == \"scissors\" :\n", + " return player_plays_bonus.i\n", + " elif player_plays_bonus.i == \"lizard\" :\n", + " return player_plays_bonus.i\n", + " elif player_plays_bonus.i == \"spock\" :\n", + " return player_plays_bonus.i\n", + "\n", + "def round_winner_bonus() :\n", + " cpu_plays_bonus()\n", + " player_plays_bonus()\n", + " if cpu_plays_bonus.i == player_plays_bonus.i :\n", + " return 0\n", + " elif (cpu_plays_bonus.i == \"rock\" and (player_plays_bonus.i == \"scissors\" or player_plays_bonus.i == \"lizard\")) or (cpu_plays_bonus.i == \"scissors\" and (player_plays_bonus.i == \"paper\" or player_plays_bonus.i == \"lizard\")) or (cpu_plays_bonus.i == \"paper\" and (player_plays_bonus.i == \"rock\" or player_plays_bonus.i == \"spock\")) or (cpu_plays_bonus.i == \"lizard\" and (player_plays_bonus.i == \"paper\" or player_plays_bonus.i == \"spock\")) or (cpu_plays_bonus.i == \"spock\" and (player_plays_bonus.i == \"scissors\" or player_plays_bonus.i == \"rock\")) :\n", + " return 1\n", + " else :\n", + " return 2\n", + "\n", + "def results_bonus() :\n", + " result_bonus = round_winner_bonus()\n", + " global cpu_score_bonus\n", + " global player_score_bonus\n", + " print(\"player plays:\", player_plays_bonus.i)\n", + " print(\"cpu plays:\", cpu_plays_bonus.i)\n", + " if result_bonus == 0 :\n", + " print(\"tie\")\n", + " if result_bonus == 1 :\n", + " cpu_score_bonus += 1\n", + " print(\"cpu wins\")\n", + " if result_bonus == 2 :\n", + " player_score_bonus += 1\n", + " print(\"player wins\")\n", + " print(\"player score =\", player_score_bonus)\n", + " print(\"cpu score =\", cpu_score_bonus)\n", + " print(\"\")\n", + "\n", + "n_rounds_bonus = \"\"\n", + "while not n_rounds_bonus.isdigit() or int(n_rounds_bonus) % 2 == 0 :\n", + " n_rounds_bonus = input(\"Number of rounds to play (it must be an odd number)? \")\n", + "n_rounds_bonus = int(n_rounds_bonus)\n", + "\n", + "rounds_to_win_bonus = n_rounds_bonus / 3\n", + "rounds_bonus = 1\n", + "while player_score_bonus < rounds_to_win_bonus and cpu_score_bonus < rounds_to_win_bonus and rounds_bonus <= n_rounds_bonus :\n", + " results_bonus()\n", + " rounds_bonus += 1\n", + " \n", + "if player_score_bonus > cpu_score_bonus :\n", + " print(\"Player wins!\")\n", + "elif cpu_score_bonus > player_score_bonus :\n", + " print(\"Cpu wins!\")\n", + "else :\n", + " print(\"Tie\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -226,7 +554,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "nbformat": 4, diff --git a/2.-Statistics/Print screens.pptx b/2.-Statistics/Print screens.pptx new file mode 100644 index 0000000..d037fa6 Binary files /dev/null and b/2.-Statistics/Print screens.pptx differ diff --git a/robot.md b/robot.md new file mode 100644 index 0000000..e69de29