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..cd7c4c6a6 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": 1, "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": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "days = 0" + ] }, { "cell_type": "markdown", @@ -58,10 +65,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 30 True\n", + "2 40 True\n", + "3 50 True\n", + "4 60 True\n", + "5 70 True\n", + "6 80 True\n", + "7 90 True\n", + "8 100 True\n", + "9 110 True\n", + "10 120 True\n", + "11 130 False\n", + "It will take the snail 11 days to escape the well\n" + ] + } + ], + "source": [ + "while snail_position <= well_height:\n", + " days += 1\n", + " snail_position += daily_distance\n", + " print(days, snail_position, snail_position <= well_height)\n", + " if snail_position <= well_height:\n", + " snail_position += nightly_distance\n", + " else:\n", + " print(\"It will take the snail\", days, \"days to escape the well\")" + ] }, { "cell_type": "markdown", @@ -72,10 +107,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It will take the snail 11 days to escape the well\n" + ] + } + ], + "source": [ + "print(\"It will take the snail\", days, \"days to escape the well\")" + ] }, { "cell_type": "markdown", @@ -96,10 +141,42 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 6, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 1 30\n", + "2 2 21\n", + "3 3 33\n", + "4 4 77\n", + "5 5 44\n", + "6 6 45\n", + "It will take the snail 6 days to escape the well\n" + ] + } + ], + "source": [ + "well_height = 125\n", + "nightly_distance = -20\n", + "snail_position = 0\n", + "days = 0\n", + "advance_cm = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "\n", + "while snail_position <= well_height:\n", + " days += 1\n", + " snail_position += advance_cm[days-1]\n", + " print(days, days, advance_cm[days-1])\n", + " #snail_position += advance_cm[days-1]\n", + " if snail_position <= well_height:\n", + " snail_position += nightly_distance\n", + " else:\n", + " print(\"It will take the snail\", days, \"days to escape the well\")" + ] }, { "cell_type": "markdown", @@ -111,10 +188,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "maximum displacement in one day is 57 and minimum displacement in one day is 1\n" + ] + } + ], + "source": [ + "max_displacement=max(advance_cm[:6]) + nightly_distance\n", + "min_displacement=min(advance_cm[:6]) + nightly_distance\n", + "print(\"maximum displacement in one day is\", max_displacement, \"and minimum displacement in one day is\", min_displacement)" + ] }, { "cell_type": "markdown", @@ -125,10 +214,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "average displacement in one day is 21.666666666666664\n" + ] + } + ], + "source": [ + "average_displacement= sum(advance_cm[:6])/len(advance_cm[:6]) + nightly_distance\n", + "print(\"average displacement in one day is\", average_displacement)" + ] }, { "cell_type": "markdown", @@ -137,6 +237,33 @@ "#### 4. What is the standard deviation of its displacement? Take into account the snail slides at night." ] }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation of its displacement is 23.752937085800994\n" + ] + } + ], + "source": [ + "import math \n", + "\n", + "advance_std_dv = 0\n", + "\n", + "for cms in advance_cm:\n", + " advance_std_dv += (average_displacement - cms)**2 \n", + " \n", + "advance_std_dv = advance_std_dv / len(advance_cm) \n", + "\n", + "advance_std_dv = math.sqrt(advance_std_dv)\n", + "print(\"The standard deviation of its displacement is\", advance_std_dv)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -161,7 +288,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.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 b4a5f6d7e..d33ace2ad 100644 --- a/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb +++ b/1.-Python/2.-Duel-of-Sorcerers/duel-of-sorcerers.ipynb @@ -49,10 +49,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "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": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0" + ] }, { "cell_type": "markdown", @@ -78,10 +85,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 10 23\n", + "saruman wins\n", + "1 11 66\n", + "saruman wins\n", + "2 13 12\n", + "gandalf wins\n", + "3 30 43\n", + "saruman wins\n", + "4 22 12\n", + "gandalf wins\n", + "5 11 10\n", + "gandalf wins\n", + "6 10 44\n", + "saruman wins\n", + "7 33 23\n", + "gandalf wins\n", + "8 22 12\n", + "gandalf wins\n", + "9 22 17\n", + "gandalf wins\n" + ] + } + ], + "source": [ + "for spells in range(len(gandalf)):\n", + " \n", + " print(spells, gandalf[spells], saruman[spells])\n", + " \n", + " if gandalf[spells] > saruman[spells]:\n", + " gandalf_wins += 1\n", + " print(\"gandalf wins\")\n", + " elif saruman[spells] > gandalf[spells]:\n", + " saruman_wins += 1\n", + " print(\"saruman wins\")\n" + ] }, { "cell_type": "markdown", @@ -93,10 +138,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf wins with 6 wins\n" + ] + } + ], + "source": [ + "if gandalf_wins > saruman_wins:\n", + " print(\"Gandalf wins with\", gandalf_wins, \"wins\")\n", + "elif gandalf_wins < saruman_wins:\n", + " print(\"Saruman wins with\", saruman_wins, \"wins\")\n", + "else:\n", + " print(\"It's a tie\")" + ] }, { "cell_type": "markdown", @@ -128,10 +188,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "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", + "\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", + "spells = 0" + ] }, { "cell_type": "markdown", @@ -142,10 +217,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalfs_wins = 0\n", + "saruman_wins = 0" + ] }, { "cell_type": "markdown", @@ -156,10 +234,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandal_power = 0\n", + "saruman_power = 0" + ] }, { "cell_type": "markdown", @@ -171,10 +252,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "gandalf wins\n" + ] + } + ], + "source": [ + "\n", + "\n", + "for spells in range(len(gandalf)):\n", + " \n", + " gandalf_spell = gandalf[spells]\n", + " gandalf_power = POWER[gandalf_spell]\n", + " \n", + " saruman_spell = saruman[spells]\n", + " saruman_power = POWER[saruman_spell]\n", + " \n", + " if gandalf_power > saruman_power:\n", + " gandalf_wins += 1\n", + " saruman_wins = 0\n", + " \n", + " elif saruman_power > gandalf_power:\n", + " saruman_wins += 1\n", + " gandalf_wins = 0\n", + " \n", + " else:\n", + " saruman_wins = 0\n", + " gandalf_wins = 0\n", + " \n", + " if gandalf_wins == 3:\n", + " print(\"gandalf wins\")\n", + " break\n", + " \n", + " if saruman_wins ==3 :\n", + " print(\"saruman wins\")\n", + " break" + ] }, { "cell_type": "markdown", @@ -185,10 +304,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "gandalfs average power: 39.0\n", + "saruman average power: 30.5\n" + ] + } + ], + "source": [ + "gandalf_power_list = []\n", + "saruman_power_list = []\n", + "\n", + "for spells in range(len(gandalf)):\n", + " \n", + " gandalfs_spell = gandalf[spells]\n", + " gandalfs_power = POWER[gandalfs_spell]\n", + " gandalf_power_list.append(gandalfs_power)\n", + " \n", + " saruman_spell = saruman[spells]\n", + " saruman_power = POWER[saruman_spell]\n", + " saruman_power_list.append(saruman_power)\n", + " \n", + "average_gandalf_power = sum(gandalf_power_list) / len(gandalf_power_list)\n", + "average_saruman_power = sum(saruman_power_list) / len(saruman_power_list)\n", + " \n", + "print(\"gandalfs average power: \", average_gandalf_power)\n", + "print(\"saruman average power: \", average_saruman_power)" + ] }, { "cell_type": "markdown", @@ -197,6 +344,28 @@ "#### 6. Find the standard deviation of the spell power of Gandalf and Saruman. " ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation of gandalf spell power is 15.951314818673865\n", + "The standard deviation of saruman power is 30.5\n" + ] + } + ], + "source": [ + "import statistics\n", + "standard_gandalf = statistics.stdev(gandalf_power_list)\n", + "standard_saruman = statistics.stdev(saruman_power_list)\n", + "print(\"The standard deviation of gandalf spell power is\", standard_gandalf)\n", + "print(\"The standard deviation of saruman power is\", average_saruman_power)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -221,7 +390,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.4" } }, "nbformat": 4, diff --git a/1.-Python/3.-Bus/bus.ipynb b/1.-Python/3.-Bus/bus.ipynb index 31f09b8fd..59f30d0e6 100644 --- a/1.-Python/3.-Bus/bus.ipynb +++ b/1.-Python/3.-Bus/bus.ipynb @@ -35,12 +35,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Variables\n", - "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]" + "stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8), (4, 6), (2, 3)]\n" ] }, { @@ -52,25 +51,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(stops)" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### 2. Assign to a variable a list whose elements are the number of passengers at each stop (in-out).\n", - "Each item depends on the previous item in the list + in - out." + "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.\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "[10, 13, 11, 10, 14, 10, 7, 5, 4]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "passengers_total = 0\n", + "passengers = []\n", + "\n", + "for stop in stops:\n", + " passengers_total += stop[0]\n", + " passengers_total -= stop[1]\n", + " passengers.append(passengers_total)\n", + " \n", + "\n", + "passengers" + ] }, { "cell_type": "markdown", @@ -81,10 +115,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The maximum occupation of the bus is: 14\n", + "The stop with maximum occupations: 4\n" + ] + } + ], + "source": [ + "for stop in range(len(passengers)):\n", + " if passengers[stop] == max(passengers):\n", + " print(\"The maximum occupation of the bus is:\", passengers[stop])\n", + " print(\"The stop with maximum occupations:\", stop)" + ] }, { "cell_type": "markdown", @@ -93,6 +141,29 @@ "#### 4. Calculate the average occupation. And the standard deviation." ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average occupation is: 9.333333333333334\n", + "The standard deviation of the bus occupation is 3.391164991562634\n" + ] + } + ], + "source": [ + "average_occupation = sum(passengers) / len(passengers)\n", + "print(\"The average occupation is:\", average_occupation)\n", + "\n", + "import statistics\n", + "stdard_dev_passengers = statistics.stdev(passengers)\n", + "print(\"The standard deviation of the bus occupation is\", stdard_dev_passengers)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -117,7 +188,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.4" } }, "nbformat": 4, diff --git a/1.-Python/4.-Robin-Hood/robin-hood.ipynb b/1.-Python/4.-Robin-Hood/robin-hood.ipynb index 01de29d3b..e7ef4e157 100644 --- a/1.-Python/4.-Robin-Hood/robin-hood.ipynb +++ b/1.-Python/4.-Robin-Hood/robin-hood.ipynb @@ -38,12 +38,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "22" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "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)]" + " (-4, 7), (-1, 3), (-3, 2), (-4, -5), (-3, 2), (5, 7), (5, 7), (2, 2), (9, 9), (-8, -9)]\n", + "\n", + "len(points)" ] }, { @@ -55,10 +68,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "there are 6 equal shots\n" + ] + } + ], + "source": [ + "equal_shots = 0\n", + "\n", + "for i in range(len(points)):\n", + " \n", + " point1 = points[i]\n", + " for j in range(i+1):\n", + " point2 = points[j]\n", + "\n", + " if point1 == point2 and i!=j:\n", + " equal_shots += 1\n", + " \n", + "print(\"there are\", equal_shots, \"equal shots\")" + ] }, { "cell_type": "markdown", @@ -70,10 +104,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The following arroes fall in Quarter 1: 10 ; Quarter 2: 6 ; Quarter 3: 2 ; and Quarter 4: 2 .\n", + "Arrows that don't fall in any quarter: 2\n" + ] + } + ], + "source": [ + "q1 = 0\n", + "q2 = 0\n", + "q3 = 0\n", + "q4 = 0\n", + "no_quarter = 0\n", + "\n", + "for i in range(len(points)):\n", + " if points[i][0] > 0 and points[i][1] > 0:\n", + " q1 += 1\n", + " elif points[i][0] < 0 and points[i][1] > 0: \n", + " q2 += 1\n", + " elif points[i][0] > 0 and points[i][1] < 0: \n", + " q3 += 1\n", + " elif points[i][0] < 0 and points[i][1] < 0: \n", + " q4 += 1\n", + " elif points[i][0] == 0 or points[i][1] == 0: \n", + " no_quarter += 1 \n", + "print(\"The following arroes fall in Quarter 1:\", q1,\n", + " \"; Quarter 2:\", q2,\n", + " \"; Quarter 3:\", q3,\n", + " \"; and Quarter 4:\", q4, \".\")\n", + "print(\"Arrows that don't fall in any quarter:\", no_quarter)\n" + ] }, { "cell_type": "markdown", @@ -88,19 +154,81 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "minimum distance: 2.0 for point (0, 2)\n", + "other point with same distance (0, -2)\n" + ] + } + ], + "source": [ + "import math\n", + "\n", + "min_dist=None\n", + "min_index=None\n", + "\n", + "def distance_to_center(p):\n", + " return math.sqrt(p[0]*p[0] + p[1]*p[1])\n", + "\n", + "for i in range(len(points)):\n", + " \n", + " p = points[i]\n", + " dist = distance_to_center(p)\n", + " \n", + " if min_dist==None:\n", + " min_dist=dist\n", + " min_index=i\n", + " elif dist 9:\n", + " counter += 1\n", + " \n", + "print(\"Arrows that hit outside a radius of 9:\", counter) " + ] + }, { "cell_type": "code", "execution_count": null, @@ -125,7 +253,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.4" } }, "nbformat": 4, diff --git a/1.-Python/5.-Temperature-Processor/temperature.ipynb b/1.-Python/5.-Temperature-Processor/temperature.ipynb index 4b597aa20..63496fbbc 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": 1, "metadata": {}, "outputs": [], "source": [ @@ -53,10 +53,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "min_temperature = min(temperatures_C)\n", + "print(min_temperature)" + ] }, { "cell_type": "markdown", @@ -67,10 +78,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "90\n" + ] + } + ], + "source": [ + "max_temperature = max(temperatures_C)\n", + "print(max_temperature)" + ] }, { "cell_type": "markdown", @@ -81,10 +103,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[70, 76, 80, 81, 80, 83, 90, 79]\n" + ] + } + ], + "source": [ + "temps_greater_70 = []\n", + "\n", + "for temp in temperatures_C:\n", + " if temp >= 70:\n", + " temps_greater_70.append(temp)\n", + " \n", + "print(temps_greater_70)" + ] }, { "cell_type": "markdown", @@ -95,10 +133,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.25\n" + ] + } + ], + "source": [ + "average_temperature = sum(temperatures_C) / len(temperatures_C)\n", + "print(average_temperature)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.25\n" + ] + } + ], + "source": [ + "import statistics\n", + "average_temperature=statistics.mean(temperatures_C)\n", + "print(average_temperature)" + ] }, { "cell_type": "markdown", @@ -109,10 +177,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "62.0\n" + ] + } + ], + "source": [ + "temperatures_C[3] = (temperatures_C[2] + temperatures_C[4]) / 2\n", + "print(temperatures_C[3])" + ] }, { "cell_type": "markdown", @@ -128,10 +207,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[91.4, 150.8, 149.0, 143.60000000000002, 138.2, 140.0, 143.60000000000002, 147.2, 158.0, 168.8, 176.0, 177.8, 176.0, 181.4, 194.0, 174.20000000000002, 141.8, 127.4, 122.0, 120.2, 127.4, 118.4, 113.0, 102.2]\n" + ] + } + ], + "source": [ + "temperatures_F = []\n", + "\n", + "for temp in temperatures_C:\n", + " temp_f = (temp*1.8) + 32\n", + " temperatures_F.append(temp_f)\n", + " \n", + "print(temperatures_F)" + ] }, { "cell_type": "markdown", @@ -150,10 +245,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4 Temperatures are greater or equal to 70, the cooling system needs to be replaced\n" + ] + } + ], + "source": [ + "temps_greater_80 = []\n", + "\n", + "for temp in temperatures_C:\n", + " if temp >= 80:\n", + " temps_greater_80.append(temp)\n", + " if len(temps_greater_70) >= 4:\n", + " print(\"4 Temperatures are greater or equal to 70, the cooling system needs to be replaced\")\n", + " break\n", + " elif len(temps_greater_80) >= 1:\n", + " print(\"4 Temperatures are greater or equal to 80, the cooling system needs to be replaced\")\n", + " break\n", + " elif average_temperature > 65:\n", + " print(\"Temperature average is greater than 65, the cooling system needs to be replaced\")\n", + " break\n", + " else:\n", + " print(\"Cooling system is fine, it does not need a replacement\")\n", + " break" + ] }, { "cell_type": "markdown", @@ -175,10 +296,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "temperature is greater then 70 degrees in 4 consecutive hours at time 12\n", + "[76, 80, 81, 80]\n" + ] + } + ], + "source": [ + "counter=0\n", + "for i in range(len(temperatures_C)):\n", + "\n", + " temp=temperatures_C[i]\n", + " \n", + " #print(temp)\n", + " if temp > 70:\n", + " counter+=1\n", + " else:\n", + " counter=0\n", + " \n", + " if counter==4:\n", + " print(\"temperature is greater then 70 degrees in 4 consecutive hours at time \", i)\n", + " print(temperatures_C[i-3:i+1])" + ] }, { "cell_type": "markdown", @@ -189,10 +334,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#I'm not sure I understood the deliverable in this two questions\n", + "\n" + ] }, { "cell_type": "markdown", @@ -202,13 +350,6 @@ "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": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -218,10 +359,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average temperature in Celcius is: 62.833333333333336\n", + "The average temperature in Celcius is: 145.1\n", + "The average temperature in Celcius 62.833333333333336 is 1.8 times plus 32 the average temperature in Farenheit of 145.1\n" + ] + } + ], + "source": [ + "average_temperature_C = sum(temperatures_C) / len(temperatures_C)\n", + "\n", + "average_temperature_F = sum(temperatures_F) / len(temperatures_F)\n", + "\n", + "print(\"The average temperature in Celcius is:\", average_temperature_C)\n", + "print(\"The average temperature in Celcius is:\", average_temperature_F)\n", + "print(\"The average temperature in Celcius\", average_temperature_C, \"is 1.8 times plus 32 the average temperature in Farenheit of\", average_temperature_F)" + ] }, { "cell_type": "markdown", @@ -230,6 +389,44 @@ "#### 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": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation of the temperatures in Celcius is: 14.633485192833897\n", + "The standard deviation of the temperatures in Farenheit is: 86.38063697637592\n" + ] + } + ], + "source": [ + "import math \n", + "\n", + "temperatures_std_dv_C = 0\n", + "\n", + "for temps in temperatures_C:\n", + " temperatures_std_dv_C += (average_temperature_C - temps)**2 \n", + " \n", + "temperatures_std_dv_C = temperatures_std_dv_C / len(temperatures_C) \n", + "\n", + "temperatures_std_dv_C = math.sqrt(temperatures_std_dv_C)\n", + "print(\"The standard deviation of the temperatures in Celcius is:\", temperatures_std_dv_C)\n", + "\n", + "temperatures_std_dv_F = 0\n", + "\n", + "for temps in temperatures_F:\n", + " temperatures_std_dv_F += (average_temperature_C - temps)**2 \n", + " \n", + "temperatures_std_dv_F = temperatures_std_dv_F / len(temperatures_C) \n", + "\n", + "temperatures_std_dv_F = math.sqrt(temperatures_std_dv_F)\n", + "print(\"The standard deviation of the temperatures in Farenheit is:\", temperatures_std_dv_F)\n" + ] + }, { "cell_type": "code", "execution_count": null, @@ -254,7 +451,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.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 9e551dfd4..b0824af06 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 = [\"rock\", \"paper\", \"scissors\"]" + ] }, { "cell_type": "markdown", @@ -61,10 +65,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "n_rounds = 5" + ] }, { "cell_type": "markdown", @@ -76,10 +82,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "rounds_to_win = 3" + ] }, { "cell_type": "markdown", @@ -90,10 +98,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "cpu_score = 0\n", + "player_score = 0" + ] }, { "cell_type": "markdown", @@ -105,10 +116,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def cpu_gesture():\n", + " index = random.randint(0,2)\n", + " return gestures[index]" + ] }, { "cell_type": "markdown", @@ -120,10 +135,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def player_gesture():\n", + " p_gesture = input(\"What is your gesture? \")\n", + " if p_gesture == \"rock\":\n", + " return p_gesture\n", + " elif p_gesture == 'scissors':\n", + " return p_gesture\n", + " elif p_gesture == 'paper':\n", + " return p_gesture\n", + " else:\n", + " print(\"please print either rock, paper or scissors.\")\n", + " return player_gesture()" + ] }, { "cell_type": "markdown", @@ -135,10 +162,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def the_match(p_gest, c_gest):\n", + " if p_gest == c_gest:\n", + " return 0\n", + " if p_gest == \"rock\":\n", + " \n", + " if c_gest == \"scissors\":\n", + " return 2\n", + " if c_gest == \"paper\":\n", + " return 1\n", + " \n", + " if p_gest == \"scissors\":\n", + " \n", + " if c_gest == \"rock\":\n", + " return 1\n", + " if c_gest == \"paper\":\n", + " return 2\n", + " if p_gest == \"paper\":\n", + " \n", + " if c_gest == \"scissors\":\n", + " return 1\n", + " if c_gest == \"rock\":\n", + " return 2\n", + " \n", + " print(\"the_match(): invalid parameters\")" + ] }, { "cell_type": "markdown", @@ -150,10 +202,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#it made more sense to me to do that in the next code" + ] }, { "cell_type": "markdown", @@ -168,10 +222,75 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "starting round 0\n", + "What is your gesture? rock\n", + "player does rock computer does rock\n", + "tie\n", + "--\n", + "\n", + "starting round 1\n", + "What is your gesture? scissors\n", + "player does scissors computer does rock\n", + "computer wins round\n", + "--\n", + "\n", + "starting round 2\n", + "What is your gesture? scissor\n", + "please print either rock, paper or scissors.\n", + "What is your gesture? scissors\n", + "player does scissors computer does rock\n", + "computer wins round\n", + "--\n", + "\n", + "starting round 3\n", + "What is your gesture? rock\n", + "player does rock computer does paper\n", + "computer wins round\n", + "--\n", + "\n", + "starting round 4\n", + "What is your gesture? rock\n", + "player does rock computer does rock\n", + "tie\n", + "--\n", + "\n" + ] + } + ], + "source": [ + "cpu_score = 0\n", + "player_score = 0\n", + "\n", + "for rounds in range(n_rounds):\n", + " print(\"starting round\", rounds)\n", + " p_gest = player_gesture() \n", + " c_gest = cpu_gesture()\n", + " \n", + " print(\"player does \", p_gest, \" computer does \", c_gest)\n", + " \n", + " result=the_match(p_gest, c_gest)\n", + " \n", + " if result == 0:\n", + " print(\"tie\")\n", + " elif result == 1:\n", + " cpu_score += 1\n", + " print(\"computer wins round\")\n", + " elif result == 2:\n", + " player_score += 1\n", + " print(\"player wins round\")\n", + " \n", + "\n", + " \n", + " print(\"--\")\n", + " print()" + ] }, { "cell_type": "markdown", @@ -183,10 +302,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Computer won the match\n" + ] + } + ], + "source": [ + "if cpu_score > player_score:\n", + " print(\"Computer won the match\")\n", + "if player_score > cpu_score:\n", + " print(\"Player won the match\")" + ] }, { "cell_type": "markdown", @@ -202,6 +334,171 @@ "**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": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "how many rounds do you want to play? Please enter an uneven number6\n", + "Please select an uneven number \n", + "how many rounds do you want to play? Please enter an uneven number5\n", + "starting round 0\n", + "What is your gesture? scissors\n", + "player does scissors computer does spock\n", + "computer wins round\n", + "--\n", + "\n", + "starting round 1\n", + "What is your gesture? lizard\n", + "player does lizard computer does scissors\n", + "computer wins round\n", + "--\n", + "\n", + "starting round 2\n", + "What is your gesture? rock\n", + "player does rock computer does paper\n", + "computer wins round\n", + "stopping the game earlier\n", + "cpu wins the match\n" + ] + } + ], + "source": [ + "gestures_2 = [\"rock\", \"paper\", \"scissors\", \"lizard\", \"spock\"]\n", + "n_of_rounds_2 = 0\n", + "rounds_to_win_2 = 0\n", + "cpu_score_2 = 0\n", + "player_score_2 = 0\n", + "\n", + "def cpu_gesture_2():\n", + " \n", + " index = random.randint(0,4)\n", + " return gestures_2[index]\n", + "\n", + "def player_gesture_2():\n", + " \n", + " p_gesture = input(\"What is your gesture? \")\n", + " \n", + " if p_gesture == \"rock\":\n", + " return p_gesture\n", + " elif p_gesture == 'scissors':\n", + " return p_gesture\n", + " elif p_gesture == 'paper':\n", + " return p_gesture\n", + " elif p_gesture == 'lizard':\n", + " return p_gesture \n", + " elif p_gesture == 'spock':\n", + " return p_gesture \n", + " else:\n", + " print(\"please print either rock, paper, scissors, lizard or spock.\")\n", + " return player_gesture_2()\n", + " \n", + "def number_of_rounds():\n", + " n_of_rounds_2 = int(input(\"how many rounds do you want to play? Please enter an uneven number\"))\n", + " if (n_of_rounds_2 % 2) == 1:\n", + " return n_of_rounds_2\n", + " else:\n", + " print(\"Please select an uneven number \")\n", + " return number_of_rounds()\n", + " \n", + "def the_match_2(p_gest, c_gest):\n", + " if p_gest == c_gest:\n", + " return 0\n", + " if p_gest == \"rock\":\n", + " \n", + " if c_gest == \"scissors\":\n", + " return 2\n", + " if c_gest == \"paper\":\n", + " return 1\n", + " if c_gest == \"lizard\":\n", + " return 2\n", + " if c_gest == \"spock\":\n", + " return 1\n", + " \n", + " if p_gest == \"scissors\":\n", + " \n", + " if c_gest == \"rock\":\n", + " return 1\n", + " if c_gest == \"paper\":\n", + " return 2\n", + " if c_gest == \"lizard\":\n", + " return 2\n", + " if c_gest == \"spock\":\n", + " return 1\n", + " \n", + " if p_gest == \"paper\":\n", + " \n", + " if c_gest == \"scissors\":\n", + " return 1\n", + " if c_gest == \"rock\":\n", + " return 2\n", + " if c_gest == \"lizard\":\n", + " return 1\n", + " if c_gest == \"spock\":\n", + " return 2\n", + " \n", + " if p_gest == \"lizard\":\n", + " if c_gest == \"scissors\":\n", + " return 1\n", + " if c_gest == \"rock\":\n", + " return 1\n", + " if c_gest == \"paper\":\n", + " return 2\n", + " if c_gest == \"spock\":\n", + " return 2\n", + " \n", + " if p_gest == \"spock\":\n", + " if c_gest == \"scissors\":\n", + " return 2\n", + " if c_gest == \"rock\":\n", + " return 2\n", + " if c_gest == \"paper\":\n", + " return 1\n", + " if c_gest == \"lizard\":\n", + " return 1\n", + " \n", + "cpu_score_2 = 0\n", + "player_score_2 = 0\n", + "\n", + "n_of_rounds_2 = number_of_rounds()\n", + "\n", + "for rounds in range(n_of_rounds_2):\n", + " print(\"starting round\", rounds)\n", + " p_gest = player_gesture_2() \n", + " c_gest = cpu_gesture_2()\n", + " \n", + " print(\"player does \", p_gest, \" computer does \", c_gest)\n", + " \n", + " result = the_match_2(p_gest, c_gest)\n", + " \n", + " if result == 0:\n", + " print(\"tie\")\n", + " elif result == 1:\n", + " cpu_score_2 += 1\n", + " print(\"computer wins round\")\n", + " elif result == 2:\n", + " player_score_2 += 1\n", + " print(\"player wins round\")\n", + " \n", + " if player_score_2 > n_of_rounds_2/2 or cpu_score_2 > n_of_rounds_2 / 2:\n", + " print(\"stopping the game earlier\")\n", + " break\n", + " \n", + " print(\"--\")\n", + " print()\n", + " \n", + "if player_score_2 > cpu_score_2:\n", + " print(\"player wins the match\")\n", + "elif cpu_score_2 > player_score_2:\n", + " print(\"cpu wins the match\")\n", + "else:\n", + " print(\"it's a tie\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -226,7 +523,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.4" } }, "nbformat": 4, diff --git a/2.-Statistics/Week 1 - Graded Quiz.png b/2.-Statistics/Week 1 - Graded Quiz.png new file mode 100644 index 000000000..176e14aa4 Binary files /dev/null and b/2.-Statistics/Week 1 - Graded Quiz.png differ diff --git a/2.-Statistics/Week 1 - Quiz on Sets.png b/2.-Statistics/Week 1 - Quiz on Sets.png new file mode 100644 index 000000000..52e444bf3 Binary files /dev/null and b/2.-Statistics/Week 1 - Quiz on Sets.png differ diff --git a/2.-Statistics/Week 1 - Quiz on Simplification Rukes and Sigma Notation.png b/2.-Statistics/Week 1 - Quiz on Simplification Rukes and Sigma Notation.png new file mode 100644 index 000000000..05d2a68a2 Binary files /dev/null and b/2.-Statistics/Week 1 - Quiz on Simplification Rukes and Sigma Notation.png differ diff --git a/2.-Statistics/Week 1 - Quiz on the Number line, including inequalities.png b/2.-Statistics/Week 1 - Quiz on the Number line, including inequalities.png new file mode 100644 index 000000000..296c7f09b Binary files /dev/null and b/2.-Statistics/Week 1 - Quiz on the Number line, including inequalities.png differ diff --git a/2.-Statistics/Week 2 - Graded Quiz.png b/2.-Statistics/Week 2 - Graded Quiz.png new file mode 100644 index 000000000..e4892e311 Binary files /dev/null and b/2.-Statistics/Week 2 - Graded Quiz.png differ diff --git a/2.-Statistics/Week 2 - Quiz on Cartesian Plane.png b/2.-Statistics/Week 2 - Quiz on Cartesian Plane.png new file mode 100644 index 000000000..139f8aac5 Binary files /dev/null and b/2.-Statistics/Week 2 - Quiz on Cartesian Plane.png differ diff --git a/2.-Statistics/Week 2 - Quiz on Types of Functions.png b/2.-Statistics/Week 2 - Quiz on Types of Functions.png new file mode 100644 index 000000000..5887d2441 Binary files /dev/null and b/2.-Statistics/Week 2 - Quiz on Types of Functions.png differ diff --git a/2.-Statistics/Week 3 - Graded Quiz.png b/2.-Statistics/Week 3 - Graded Quiz.png new file mode 100644 index 000000000..5d7b965ac Binary files /dev/null and b/2.-Statistics/Week 3 - Graded Quiz.png differ diff --git a/2.-Statistics/Week 3 - Quiz on Exponents and Logarithms .png b/2.-Statistics/Week 3 - Quiz on Exponents and Logarithms .png new file mode 100644 index 000000000..c1e738d9e Binary files /dev/null and b/2.-Statistics/Week 3 - Quiz on Exponents and Logarithms .png differ diff --git a/2.-Statistics/Week 3 - Quiz on Tangent Lines to Functions.png b/2.-Statistics/Week 3 - Quiz on Tangent Lines to Functions.png new file mode 100644 index 000000000..92b77448d Binary files /dev/null and b/2.-Statistics/Week 3 - Quiz on Tangent Lines to Functions.png differ diff --git a/2.-Statistics/Week 4 - Graded Quiz.png b/2.-Statistics/Week 4 - Graded Quiz.png new file mode 100644 index 000000000..9c4dda79e Binary files /dev/null and b/2.-Statistics/Week 4 - Graded Quiz.png differ diff --git a/2.-Statistics/Week 4 - Quiz on Bayer Theorem and the Binomial Theorem.png b/2.-Statistics/Week 4 - Quiz on Bayer Theorem and the Binomial Theorem.png new file mode 100644 index 000000000..091ca901b Binary files /dev/null and b/2.-Statistics/Week 4 - Quiz on Bayer Theorem and the Binomial Theorem.png differ diff --git a/2.-Statistics/Week 4 - Quiz on Probability Concepts.png b/2.-Statistics/Week 4 - Quiz on Probability Concepts.png new file mode 100644 index 000000000..395c5097d Binary files /dev/null and b/2.-Statistics/Week 4 - Quiz on Probability Concepts.png differ diff --git a/2.-Statistics/Week 4 - Quiz on Problem Solving.png b/2.-Statistics/Week 4 - Quiz on Problem Solving.png new file mode 100644 index 000000000..7ed42c0fb Binary files /dev/null and b/2.-Statistics/Week 4 - Quiz on Problem Solving.png differ diff --git a/robot.md b/robot.md new file mode 100644 index 000000000..e69de29bb