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..ad918fa 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,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "while (snail_position < well_height):\n", + " snail_position += daily_distance + nightly_distance\n", + " days += 1" + ] }, { "cell_type": "markdown", @@ -72,10 +83,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The snail needs 13 days to reach the top of the well.\n" + ] + } + ], + "source": [ + "print (\"The snail needs \"+ str(days) +\" days to reach the top of the well.\")" + ] }, { "cell_type": "markdown", @@ -96,10 +117,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The snail needs 6 days to reach the top of the well.\n" + ] + } + ], + "source": [ + "well_height = 125\n", + "daily_distance = [30, 21, 33, 77, 44, 45, 23, 45, 12, 34, 55]\n", + "nightly_distance = -20\n", + "snail_position = 0\n", + "\n", + "days = 0\n", + "\n", + "while (snail_position < well_height):\n", + " snail_position += daily_distance[days] + nightly_distance\n", + " days += 1\n", + " \n", + "print (\"The snail needs \"+ str(days) +\" days to reach the top of the well.\")" + ] }, { "cell_type": "markdown", @@ -111,10 +153,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The maximun displacement is: 77\n", + "The minimum displacement is: 12\n", + "The displacement to get out of the well was 250 cm\n" + ] + } + ], + "source": [ + "print (\"The maximun displacement is: \"+ str(max(daily_distance)))\n", + "print (\"The minimum displacement is: \"+ str(min(daily_distance)))\n", + "\n", + "print(\"The displacement to get out of the well was \"+ str(sum(daily_distance[:days])) +\" cm\")" + ] }, { "cell_type": "markdown", @@ -125,10 +182,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average progress is 21.666666666666668\n" + ] + } + ], + "source": [ + "daily_progress = []\n", + "for distance in daily_distance[:days] : \n", + " daily_progress.append(distance + nightly_distance)\n", + "\n", + "mean = sum(daily_progress)/len(daily_progress)\n", + "\n", + "print (\"The average progress is \"+str(mean))" + ] }, { "cell_type": "markdown", @@ -139,10 +212,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviaton of its displacement is 17.81073334319006\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "\n", + "denominator = 0\n", + "for progress in daily_progress: \n", + " denominator += pow(progress - mean, 2)\n", + "stdev = sqrt(denominator/len(daily_progress))\n", + "\n", + "print (\"The standard deviaton of its displacement is \"+ str(stdev))" + ] } ], "metadata": { @@ -161,7 +251,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.7" } }, "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..e5d8b87 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,15 @@ }, { "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", + "\n", + "spells = 0" + ] }, { "cell_type": "markdown", @@ -64,10 +69,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 +86,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "for gandalf_spell in gandalf : \n", + " if gandalf_spell > saruman[spells] : gandalf_wins += 1 \n", + " elif gandalf_spell < saruman[spells] : saruman_wins += 1\n", + " spells +=1" + ] }, { "cell_type": "markdown", @@ -93,10 +106,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf wins\n" + ] + } + ], + "source": [ + "if gandalf_wins == saruman_wins : print(\"Tie\")\n", + "elif gandalf_wins < saruman_wins : print(\"Saruman wins\")\n", + "else : print(\"Gandalf wins\")" + ] }, { "cell_type": "markdown", @@ -128,10 +153,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 +182,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "gandalf_wins = 0\n", + "saruman_wins = 0" + ] }, { "cell_type": "markdown", @@ -156,10 +199,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[50, 40, 40, 10, 50, 10, 40, 50, 50, 50]\n", + "[45, 45, 25, 50, 25, 40, 10, 45, 10, 10]\n" + ] + } + ], + "source": [ + "gandalf_power = []\n", + "for spell in gandalf : gandalf_power.append(POWER[spell])\n", + "print (gandalf_power)\n", + " \n", + " \n", + "saruman_power = []\n", + "for spell in saruman : saruman_power.append(POWER[spell])\n", + "print(saruman_power)" + ] }, { "cell_type": "markdown", @@ -171,10 +232,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tie\n" + ] + } + ], + "source": [ + "while ((gandalf_wins & saruman_wins)<2):\n", + "\n", + " for gandalf_pow in gandalf_power : \n", + " if gandalf_pow > saruman_power[spells] : gandalf_wins += 1 \n", + " elif gandalf_pow < saruman_power[spells] : saruman_wins += 1\n", + " spells +=1\n", + " \n", + "if gandalf_wins == 2 : print(\"Gandalf wins\")\n", + "elif saruman_wins == 2 : print(\"Saruman wins\")\n", + "else : print(\"Tie\")" + ] }, { "cell_type": "markdown", @@ -185,10 +265,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gandalf average power: 39.0\n", + "Saruman average power: 30.5\n" + ] + } + ], + "source": [ + "gandalf_avg_power = sum(gandalf_power)/len(gandalf)\n", + "saruman_avg_power = sum(saruman_power)/len(saruman)\n", + "\n", + "print(\"Gandalf average power: \"+str(gandalf_avg_power))\n", + "print(\"Saruman average power: \"+str(saruman_avg_power))" + ] }, { "cell_type": "markdown", @@ -199,10 +294,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The standard deviation of Gandalf is 15.951314818673865\n", + "The standard deviation of Sauman is 16.40629960309962\n" + ] + } + ], + "source": [ + "from statistics import stdev\n", + "\n", + "print(\"The standard deviation of Gandalf is \"+ str(stdev(gandalf_power)))\n", + "print(\"The standard deviation of Sauman is \"+ str(stdev(saruman_power)))" + ] } ], "metadata": { @@ -221,7 +330,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.7" } }, "nbformat": 4, diff --git a/1.-Python/3.-Bus/bus.ipynb b/1.-Python/3.-Bus/bus.ipynb index 31f09b8..cdc5642 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,21 @@ }, { "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": [ + "n_stops = len(stops)\n", + "print (\"Number of stops: \"+str(n_stops))" + ] }, { "cell_type": "markdown", @@ -67,10 +78,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Occupation in each stop: [10, 13, 11, 10, 14, 10, 7, 5, 4]\n" + ] + } + ], + "source": [ + "n_passengers = []\n", + "passengers = 0\n", + "\n", + "for stop in stops :\n", + " passengers += stop[0]-stop[1]\n", + " n_passengers.append(passengers)\n", + "\n", + "print (\"Occupation in each stop: \"+str(n_passengers))" + ] }, { "cell_type": "markdown", @@ -81,10 +109,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Maximum occupation: 14\n" + ] + } + ], + "source": [ + "print (\"Maximum occupation: \"+str(max(n_passengers)))" + ] }, { "cell_type": "markdown", @@ -95,10 +133,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average occupation: 9.333333333333334\n", + "Standard deviation: 3.391164991562634\n" + ] + } + ], + "source": [ + "avg = sum(n_passengers)/n_stops\n", + "print (\"Average occupation: \"+str(avg))\n", + "\n", + "from statistics import stdev\n", + "print (\"Standard deviation: \"+str(stdev(n_passengers)))\n" + ] } ], "metadata": { @@ -117,7 +170,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.7" } }, "nbformat": 4, diff --git a/1.-Python/4.-Robin-Hood/robin-hood.ipynb b/1.-Python/4.-Robin-Hood/robin-hood.ipynb index 01de29d..11dfa56 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,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "{(-3, 2), (2, 2), (4, 5), (5, 7)}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set([(x,y) for (x,y) in points if points.count((x,y)) > 1])" + ] }, { "cell_type": "markdown", @@ -70,10 +83,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Q1: 10\n", + "Q2: 6\n", + "Q3: 2\n", + "Q4: 2\n" + ] + } + ], + "source": [ + "Q1 = 0\n", + "Q2 = 0\n", + "Q3 = 0\n", + "Q4 = 0\n", + "\n", + "for point in points: \n", + " if point[0]>0:\n", + " if point[1]>0: Q1 += 1\n", + " elif point[1]<0: Q4 += 1\n", + " elif point[0]<0:\n", + " if point[1]>0: Q2 += 1\n", + " elif point[1]<0: Q3 += 1\n", + " \n", + "print (\"Q1: \"+str(Q1))\n", + "print (\"Q2: \"+str(Q2))\n", + "print (\"Q3: \"+str(Q3))\n", + "print (\"Q4: \"+str(Q4))" + ] }, { "cell_type": "markdown", @@ -88,10 +130,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Closest point: (0, 2)\n", + "Closest point: (0, -2)\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "\n", + "def centering (x,y):\n", + " return sqrt((x)**2 + (y)**2)\n", + "\n", + "dist = []\n", + "\n", + "for point in points: \n", + " dist.append(centering(point[0],point[1]))\n", + " \n", + "min_dist = min(dist)\n", + "\n", + "indices = [i for i, x in enumerate(dist) if x == min_dist]\n", + "\n", + "for index in indices: \n", + " print (\"Closest point: \"+ str(points[index]))\n" + ] }, { "cell_type": "markdown", @@ -103,10 +171,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Missing arrows: 2\n" + ] + } + ], + "source": [ + "missing = 0\n", + "\n", + "for d in dist:\n", + " if (d >= 9) : missing +=1 \n", + "\n", + "print (\"Missing arrows: \"+str(missing))" + ] } ], "metadata": { @@ -125,7 +208,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.7" } }, "nbformat": 4, diff --git a/1.-Python/5.-Temperature-Processor/temperature.ipynb b/1.-Python/5.-Temperature-Processor/temperature.ipynb index 4b597aa..631827a 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,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "min_temp = min(temperatures_C)" + ] }, { "cell_type": "markdown", @@ -67,10 +69,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "max_temp = max(temperatures_C)" + ] }, { "cell_type": "markdown", @@ -81,10 +85,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "high_temp = []\n", + "\n", + "for temp in temperatures_C:\n", + " if temp >= 70 : high_temp.append(temp)" + ] }, { "cell_type": "markdown", @@ -95,10 +104,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "avg_temp = sum(temperatures_C)/len(temperatures_C)" + ] }, { "cell_type": "markdown", @@ -109,10 +120,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "temperatures_C[3] = (temperatures_C[2]+temperatures_C[4])/2" + ] }, { "cell_type": "markdown", @@ -128,10 +141,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "temperatures_F = []\n", + "\n", + "for temp in temperatures_C :\n", + " temperatures_F.append((1.8*temp)+32)" + ] }, { "cell_type": "markdown", @@ -150,10 +168,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cooling system needs to be changed\n" + ] + } + ], + "source": [ + "if ((len(high_temp)>4) | (max_temp > 80) | (avg_temp > 65)) : print (\"Cooling system needs to be changed\")\n", + "else: print (\"Cooling system OK\")" + ] }, { "cell_type": "markdown", @@ -175,10 +204,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[8, 9, 10, 11, 12, 13, 14, 15]\n" + ] + } + ], + "source": [ + "high_temp_hours = []\n", + "\n", + "i = 0\n", + "for temp in temperatures_C:\n", + " if temp >= 70 : \n", + " high_temp.append(temp)\n", + " high_temp_hours.append(i)\n", + " i+=1\n", + " \n", + "print(high_temp_hours)" + ] }, { "cell_type": "markdown", @@ -189,10 +237,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are more than 4 consecutive hours\n" + ] + } + ], + "source": [ + "def consecutive (l, amount):\n", + " for i in range(len(l)-amount):\n", + " if (l[i+amount] - l[i] == amount) : \n", + " return 1\n", + " \n", + "if consecutive(high_temp_hours, 4) : print (\"There are more than 4 consecutive hours\")" + ] }, { "cell_type": "markdown", @@ -204,10 +267,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cooling system needs to be changed\n" + ] + } + ], + "source": [ + "if ((consecutive(high_temp_hours,4)) | (max_temp > 80) | (avg_temp > 65)) : print (\"Cooling system needs to be changed\")\n", + "else: print (\"Cooling system OK\")" + ] }, { "cell_type": "markdown", @@ -218,10 +292,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.25\n", + "145.1\n", + "They are proportional, following the same formula F = 1.8 * C + 32\n" + ] + } + ], + "source": [ + "avg_temp_F = sum(temperatures_F)/len(temperatures_F)\n", + "\n", + "print(avg_temp)\n", + "print(avg_temp_F)\n", + "\n", + "print(\"They are proportional, following the same formula F = 1.8 * C + 32\")" + ] }, { "cell_type": "markdown", @@ -232,10 +323,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "14.94821980579356\n", + "26.906795650428407\n", + "They are, yet again, proportional\n" + ] + } + ], + "source": [ + "from statistics import stdev\n", + "\n", + "dev_C = stdev (temperatures_C)\n", + "dev_F = stdev (temperatures_F)\n", + "\n", + "print (dev_C)\n", + "print (dev_F)\n", + "\n", + "print(\"They are, yet again, proportional\")" + ] } ], "metadata": { @@ -254,7 +365,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.7" } }, "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..e5c30bd 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": [ + "from random import choice" + ] }, { "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,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def read_rounds():\n", + " n_rounds = 0\n", + " while (n_rounds%2 != 1):\n", + " print(\"Enter the number of rounds for this game:\")\n", + " n_rounds = int(input())\n", + " if n_rounds%2 == 0 : print(\"The number of rounds must be odd\")\n", + " return n_rounds" + ] }, { "cell_type": "markdown", @@ -76,10 +88,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def get_rounds_to_win(n_rounds):\n", + " rounds_to_win = int(n_rounds/2) +1\n", + " return rounds_to_win" + ] }, { "cell_type": "markdown", @@ -90,10 +106,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 +124,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def get_gesture():\n", + " return choice(gestures)" + ] }, { "cell_type": "markdown", @@ -120,10 +142,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def ask_gesutre():\n", + " gest = \"\"\n", + " \n", + " while (not (gest in gestures)): \n", + " print(\"Select a gesture: \"+ str(gestures))\n", + " gest = input()\n", + " \n", + " return gest" + ] }, { "cell_type": "markdown", @@ -135,10 +166,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def check_win (p_gest, cpu_gest):\n", + " if p_gest == cpu_gest : return 0\n", + " elif (p_gest == \"scissors\") & (cpu_gest== \"paper\") : return 2 \n", + " elif (p_gest == \"rock\") & (cpu_gest== \"scissors\") : return 2\n", + " elif (p_gest == \"paper\") & (cpu_gest== \"rock\") : return 2\n", + " else: return 1" + ] }, { "cell_type": "markdown", @@ -150,10 +188,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def print_game(p_gest, cpu_gest, rounds, player_wins, cpu_wins):\n", + " \n", + " print(\"Player gesture: \"+ str(p_gest))\n", + " print(\"CPU gesture: \"+ str(cpu_gest))\n", + " \n", + " result = check_win(p_gest, cpu_gest)\n", + " if result == 0 : print (\"Tie\")\n", + " elif result == 1 : \n", + " print (\"CPU won\")\n", + " cpu_wins += 1\n", + "\n", + " else:\n", + " print (\"Player won\")\n", + " player_wins += 1\n", + "\n", + " rounds += 1\n", + " \n", + " return rounds, player_wins, cpu_wins\n" + ] }, { "cell_type": "markdown", @@ -168,10 +225,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the number of rounds for this game:\n", + "1\n", + "Select a gesture: ['rock', 'paper', 'scissors']\n", + "rock\n", + "Player gesture: rock\n", + "CPU gesture: scissors\n", + "Player won\n" + ] + } + ], + "source": [ + "n_rounds = read_rounds()\n", + "rounds_to_win = get_rounds_to_win(n_rounds)\n", + "\n", + "rounds = 0\n", + "player_score = 0\n", + "cpu_score = 0\n", + "\n", + "while (((player_score | cpu_score) < rounds_to_win) | (rounds < n_rounds) ):\n", + " \n", + " player_gesture = ask_gesutre()\n", + " cpu_gesture = get_gesture()\n", + " \n", + " rounds, player_score, cpu_score = print_game(player_gesture, cpu_gesture, rounds, player_score, cpu_score)" + ] }, { "cell_type": "markdown", @@ -183,10 +268,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Player won the game!\n" + ] + } + ], + "source": [ + "if player_score == rounds_to_win : print (\"Player won the game!\")\n", + "elif cpu_score == rounds_to_win : print (\"CPU won the game!\")\n", + "else: print (\"Game is tied!\")" + ] }, { "cell_type": "markdown", @@ -204,10 +301,54 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the number of rounds for this game:\n", + "1\n", + "Select a gesture: ['rock', 'paper', 'scissors', 'lizzard', 'spock']\n", + "spock\n", + "Player gesture: spock\n", + "CPU gesture: scissors\n", + "Player won\n", + "Player won the game!\n" + ] + } + ], + "source": [ + "gestures = [\"rock\",\"paper\",\"scissors\",\"lizzard\",\"spock\"]\n", + "\n", + "def check_win (p_gest, cpu_gest):\n", + " if p_gest == cpu_gest : return 0\n", + " elif (p_gest == \"scissors\") & ((cpu_gest== \"paper\")|(cpu_gest==\"lizzard\")) : return 2 \n", + " elif (p_gest == \"rock\") & ((cpu_gest== \"scissors\")|(cpu_gest==\"lizzard\")) : return 2\n", + " elif (p_gest == \"paper\") & ((cpu_gest== \"rock\")|(cpu_gest==\"spock\")) : return 2\n", + " elif (p_gest == \"lizzard\") & ((cpu_gest== \"spock\")|(cpu_gest==\"paper\")) : return 2\n", + " elif (p_gest == \"spock\") & ((cpu_gest== \"rock\")|(cpu_gest==\"scissors\")) : return 2\n", + " else: return 1\n", + " \n", + "n_rounds = read_rounds()\n", + "rounds_to_win = get_rounds_to_win(n_rounds)\n", + "\n", + "rounds = 0\n", + "player_score = 0\n", + "cpu_score = 0\n", + "\n", + "while (((player_score | cpu_score) < rounds_to_win) | (rounds < n_rounds) ):\n", + " \n", + " player_gesture = ask_gesutre()\n", + " cpu_gesture = get_gesture()\n", + " \n", + " rounds, player_score, cpu_score = print_game(player_gesture, cpu_gesture, rounds, player_score, cpu_score)\n", + " \n", + "if player_score == rounds_to_win : print (\"Player won the game!\")\n", + "elif cpu_score == rounds_to_win : print (\"CPU won the game!\")\n", + "else: print (\"Game is tied!\")" + ] } ], "metadata": { @@ -226,7 +367,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.7" } }, "nbformat": 4, diff --git a/2.-Statistics/1st-Week/NumberLineIncludingInequalities.png b/2.-Statistics/1st-Week/NumberLineIncludingInequalities.png new file mode 100644 index 0000000..568db98 Binary files /dev/null and b/2.-Statistics/1st-Week/NumberLineIncludingInequalities.png differ diff --git a/2.-Statistics/1st-Week/Sets.png b/2.-Statistics/1st-Week/Sets.png new file mode 100644 index 0000000..1f94430 Binary files /dev/null and b/2.-Statistics/1st-Week/Sets.png differ diff --git a/2.-Statistics/1st-Week/SetsNumberLineInequaitiesSimplificationAndSigmaNotation.png b/2.-Statistics/1st-Week/SetsNumberLineInequaitiesSimplificationAndSigmaNotation.png new file mode 100644 index 0000000..088d130 Binary files /dev/null and b/2.-Statistics/1st-Week/SetsNumberLineInequaitiesSimplificationAndSigmaNotation.png differ diff --git a/2.-Statistics/1st-Week/SimplificationRulesAndSigmaNotation.png b/2.-Statistics/1st-Week/SimplificationRulesAndSigmaNotation.png new file mode 100644 index 0000000..513310e Binary files /dev/null and b/2.-Statistics/1st-Week/SimplificationRulesAndSigmaNotation.png differ diff --git a/2.-Statistics/2nd-Week/CartesianPlane.png b/2.-Statistics/2nd-Week/CartesianPlane.png new file mode 100644 index 0000000..5e48817 Binary files /dev/null and b/2.-Statistics/2nd-Week/CartesianPlane.png differ diff --git a/2.-Statistics/2nd-Week/CartesianPlaneAndTypesOfFunction.png b/2.-Statistics/2nd-Week/CartesianPlaneAndTypesOfFunction.png new file mode 100644 index 0000000..93b5fd2 Binary files /dev/null and b/2.-Statistics/2nd-Week/CartesianPlaneAndTypesOfFunction.png differ diff --git a/2.-Statistics/2nd-Week/TypesOfFunctions.png b/2.-Statistics/2nd-Week/TypesOfFunctions.png new file mode 100644 index 0000000..5bfef49 Binary files /dev/null and b/2.-Statistics/2nd-Week/TypesOfFunctions.png differ diff --git a/2.-Statistics/3rd-Week/ExponentsAndLogarithms.png b/2.-Statistics/3rd-Week/ExponentsAndLogarithms.png new file mode 100644 index 0000000..51d1133 Binary files /dev/null and b/2.-Statistics/3rd-Week/ExponentsAndLogarithms.png differ diff --git a/2.-Statistics/3rd-Week/TangentLinesToFunctions.png b/2.-Statistics/3rd-Week/TangentLinesToFunctions.png new file mode 100644 index 0000000..6a6cf38 Binary files /dev/null and b/2.-Statistics/3rd-Week/TangentLinesToFunctions.png differ diff --git a/2.-Statistics/3rd-Week/TangentLinesToFunctionsExponentsAndLogarithms.png b/2.-Statistics/3rd-Week/TangentLinesToFunctionsExponentsAndLogarithms.png new file mode 100644 index 0000000..bd00df4 Binary files /dev/null and b/2.-Statistics/3rd-Week/TangentLinesToFunctionsExponentsAndLogarithms.png differ diff --git a/2.-Statistics/4th-Week/BayesTheoremAndBinomialTheorem.png b/2.-Statistics/4th-Week/BayesTheoremAndBinomialTheorem.png new file mode 100644 index 0000000..65bb5d1 Binary files /dev/null and b/2.-Statistics/4th-Week/BayesTheoremAndBinomialTheorem.png differ diff --git a/2.-Statistics/4th-Week/ProbabilityBasicAndIntermediate.png b/2.-Statistics/4th-Week/ProbabilityBasicAndIntermediate.png new file mode 100644 index 0000000..fd21e93 Binary files /dev/null and b/2.-Statistics/4th-Week/ProbabilityBasicAndIntermediate.png differ diff --git a/2.-Statistics/4th-Week/ProbabilityConcepts.png b/2.-Statistics/4th-Week/ProbabilityConcepts.png new file mode 100644 index 0000000..7dae208 Binary files /dev/null and b/2.-Statistics/4th-Week/ProbabilityConcepts.png differ diff --git a/2.-Statistics/4th-Week/ProblemSolving.png b/2.-Statistics/4th-Week/ProblemSolving.png new file mode 100644 index 0000000..916a84a Binary files /dev/null and b/2.-Statistics/4th-Week/ProblemSolving.png differ diff --git a/robot.md b/robot.md new file mode 100644 index 0000000..e69de29