From 8ffa7e1911d93d7156ab185f95878cb509895dda Mon Sep 17 00:00:00 2001 From: juan1309-ctr Date: Sun, 16 Jan 2022 18:22:33 -0600 Subject: [PATCH] =?UTF-8?q?=C2=A8Esto=20es=20=20la=20tarea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.ipynb_checkpoints/main-checkpoint.ipynb | 333 ++++++++++++------ your-code/main.ipynb | 333 ++++++++++++------ 2 files changed, 436 insertions(+), 230 deletions(-) diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb index d68aeb6..702bd13 100644 --- a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -30,23 +30,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2926" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def summation(num):\n", - " # This function returns 1+2+3+....+num\n", - " \n", - " # Your code here: " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation" + " # This function returns 1+2+3+....+numa=\n", + " a=0 \n", + " # Your code here: \n", + " for i in range(num+1):\n", + " a=a+i\n", + " return(a)\n", + "summation(num)" ] }, { @@ -60,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -69,23 +75,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27\n" + ] + } + ], "source": [ "def summation2(*args):\n", - " # This function returns the sum of *args\n", - " \n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation2" + " print(sum(args))\n", + "array=[3,8,16]\n", + "summation2(*array) \n", + "\n" ] }, { @@ -97,23 +103,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], "source": [ "def summation3(a, b, c):\n", - " # This function returns a+b+c\n", - " \n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation3" + " print(a+b+c)\n", + "summation3(1,2,3)" ] }, { @@ -125,32 +129,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "dictionary={'red':3, 'blue':8, 'green':24, 'orange':12, 'purple':10}" + "dictionary={'red':3, 'blue':8, 'green':24, 'orange':12, 'purple':10}\n", + "del dictionary['red']\n", + "dictionary\n", + "values=dictionary.values()" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def summation4(**kwargs):\n", - " # This function returns the sum of all M&Ms, except the red ones\n", - " \n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation4" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'blue': 8, 'green': 24, 'orange': 12, 'purple': 10}\n" + ] + }, + { + "data": { + "text/plain": [ + "54" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def summation5 (**kwargs):\n", + " for key, value in kwargs.items():\n", + " del kwargs['red']\n", + " print(kwargs)\n", + " values=kwargs.values()\n", + " return(sum(values))\n", + "dictionary={'red':3, 'blue':8, 'green':24, 'orange':12, 'purple':10} \n", + "summation5(**dictionary)" ] }, { @@ -162,36 +182,64 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 6, 15, 632, 112]\n" + ] + } + ], "source": [ "a=4\n", "b=6\n", "c=15\n", "d=[48, 465, 23, 96]\n", - "e={'A':16, 'B':32, 'C':64}" + "d=sum(d)\n", + "e={'A':16, 'B':32, 'C':64}\n", + "e=e.values()\n", + "e=sum(e)\n", + "valores= [a,b,c,d,e]\n", + "print(valores)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def summation5('define the function input'):\n", - " # This function returns the sum of a,b,c,d and e\n", - " # You need to define the function input\n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation5" + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 6, 15, 632, 112]\n" + ] + }, + { + "data": { + "text/plain": [ + "769" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def summation5(*args):\n", + " suma=0\n", + " for valor in args:\n", + " suma=suma+valor\n", + " return(suma)\n", + " \n", + "print(valores)\n", + "summation5(*valores)" ] }, { @@ -205,9 +253,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], "source": [ "# We first define our iterator:\n", "\n", @@ -220,9 +276,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "# We continue to iterate through the iterator.\n", "\n", @@ -231,18 +295,38 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], "source": [ "print(next(iterator))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "StopIteration", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", + "\u001b[1;32mC:\\Users\\JUANCA~1\\AppData\\Local\\Temp/ipykernel_14232/3052031144.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# After we have iterated through all elements, we will get a StopIteration Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mStopIteration\u001b[0m: " + ] + } + ], "source": [ "# After we have iterated through all elements, we will get a StopIteration Error\n", "\n", @@ -288,7 +372,10 @@ " # Sample Input: iter([1,2,3])\n", " # Sample Output: 2\n", " \n", - " # Your code here:" + " for i in iterator:\n", + " if i%2==0:\n", + " return( f'{i} es divisible entre dos')\n", + " " ] }, { @@ -297,7 +384,7 @@ "metadata": {}, "outputs": [], "source": [ - "# print divisible2" + "print(divisible2(iterator))" ] }, { @@ -350,39 +437,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "def even_iterator(n):\n", - " # This function produces an iterator containing all even numbers between 0 and n\n", - " # Input: integer\n", - " # Output: iterator\n", + " number=0\n", + " while number < n:\n", + " yield number\n", + " number=number+1\n", + " \n", " \n", - " # Sample Input: 5\n", - " # Sample Output: iter([0, 2, 4])" + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ - "# print even_iterator" + "iterator = even_iterator(8)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n" + ] + } + ], + "source": [ + "for i in iterator:\n", + " if i%2==0:\n", + " print(i)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -396,7 +499,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/your-code/main.ipynb b/your-code/main.ipynb index d68aeb6..702bd13 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -30,23 +30,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2926" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def summation(num):\n", - " # This function returns 1+2+3+....+num\n", - " \n", - " # Your code here: " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation" + " # This function returns 1+2+3+....+numa=\n", + " a=0 \n", + " # Your code here: \n", + " for i in range(num+1):\n", + " a=a+i\n", + " return(a)\n", + "summation(num)" ] }, { @@ -60,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -69,23 +75,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27\n" + ] + } + ], "source": [ "def summation2(*args):\n", - " # This function returns the sum of *args\n", - " \n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation2" + " print(sum(args))\n", + "array=[3,8,16]\n", + "summation2(*array) \n", + "\n" ] }, { @@ -97,23 +103,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], "source": [ "def summation3(a, b, c):\n", - " # This function returns a+b+c\n", - " \n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation3" + " print(a+b+c)\n", + "summation3(1,2,3)" ] }, { @@ -125,32 +129,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "dictionary={'red':3, 'blue':8, 'green':24, 'orange':12, 'purple':10}" + "dictionary={'red':3, 'blue':8, 'green':24, 'orange':12, 'purple':10}\n", + "del dictionary['red']\n", + "dictionary\n", + "values=dictionary.values()" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def summation4(**kwargs):\n", - " # This function returns the sum of all M&Ms, except the red ones\n", - " \n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation4" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'blue': 8, 'green': 24, 'orange': 12, 'purple': 10}\n" + ] + }, + { + "data": { + "text/plain": [ + "54" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def summation5 (**kwargs):\n", + " for key, value in kwargs.items():\n", + " del kwargs['red']\n", + " print(kwargs)\n", + " values=kwargs.values()\n", + " return(sum(values))\n", + "dictionary={'red':3, 'blue':8, 'green':24, 'orange':12, 'purple':10} \n", + "summation5(**dictionary)" ] }, { @@ -162,36 +182,64 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 6, 15, 632, 112]\n" + ] + } + ], "source": [ "a=4\n", "b=6\n", "c=15\n", "d=[48, 465, 23, 96]\n", - "e={'A':16, 'B':32, 'C':64}" + "d=sum(d)\n", + "e={'A':16, 'B':32, 'C':64}\n", + "e=e.values()\n", + "e=sum(e)\n", + "valores= [a,b,c,d,e]\n", + "print(valores)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def summation5('define the function input'):\n", - " # This function returns the sum of a,b,c,d and e\n", - " # You need to define the function input\n", - " # Your code here:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# print summation5" + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 6, 15, 632, 112]\n" + ] + }, + { + "data": { + "text/plain": [ + "769" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def summation5(*args):\n", + " suma=0\n", + " for valor in args:\n", + " suma=suma+valor\n", + " return(suma)\n", + " \n", + "print(valores)\n", + "summation5(*valores)" ] }, { @@ -205,9 +253,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], "source": [ "# We first define our iterator:\n", "\n", @@ -220,9 +276,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "# We continue to iterate through the iterator.\n", "\n", @@ -231,18 +295,38 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], "source": [ "print(next(iterator))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "StopIteration", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", + "\u001b[1;32mC:\\Users\\JUANCA~1\\AppData\\Local\\Temp/ipykernel_14232/3052031144.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# After we have iterated through all elements, we will get a StopIteration Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mStopIteration\u001b[0m: " + ] + } + ], "source": [ "# After we have iterated through all elements, we will get a StopIteration Error\n", "\n", @@ -288,7 +372,10 @@ " # Sample Input: iter([1,2,3])\n", " # Sample Output: 2\n", " \n", - " # Your code here:" + " for i in iterator:\n", + " if i%2==0:\n", + " return( f'{i} es divisible entre dos')\n", + " " ] }, { @@ -297,7 +384,7 @@ "metadata": {}, "outputs": [], "source": [ - "# print divisible2" + "print(divisible2(iterator))" ] }, { @@ -350,39 +437,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "def even_iterator(n):\n", - " # This function produces an iterator containing all even numbers between 0 and n\n", - " # Input: integer\n", - " # Output: iterator\n", + " number=0\n", + " while number < n:\n", + " yield number\n", + " number=number+1\n", + " \n", " \n", - " # Sample Input: 5\n", - " # Sample Output: iter([0, 2, 4])" + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ - "# print even_iterator" + "iterator = even_iterator(8)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n" + ] + } + ], + "source": [ + "for i in iterator:\n", + " if i%2==0:\n", + " print(i)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -396,7 +499,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.9.7" } }, "nbformat": 4,