diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main[Moises_Vargas]-checkpoint.ipynb similarity index 56% rename from your-code/.ipynb_checkpoints/main-checkpoint.ipynb rename to your-code/.ipynb_checkpoints/main[Moises_Vargas]-checkpoint.ipynb index d68aeb6..7f22424 100644 --- a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main[Moises_Vargas]-checkpoint.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -30,23 +30,46 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2926\n" + ] + } + ], "source": [ "def summation(num):\n", " # This function returns 1+2+3+....+num\n", - " \n", - " # Your code here: " + " resultado=sum(i for i in range(1, num+1))\n", + " return resultado\n", + " # Your code here: \n", + "\n", + "print(summation(num)) " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2926" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# print summation" + "# print summation\n", + "summation(num)" ] }, { @@ -60,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -69,23 +92,43 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "27" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def summation2(*args):\n", - " # This function returns the sum of *args\n", - " \n", - " # Your code here:" + " resultado=sum(i for i in array)\n", + " return resultado\n", + "summation2(array)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27\n" + ] + } + ], "source": [ - "# print summation2" + "# print summation2\n", + "print(summation2(array))" ] }, { @@ -97,23 +140,46 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "27" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def summation3(a, b, c):\n", " # This function returns a+b+c\n", - " \n", - " # Your code here:" + " \n", + " # Your code here:\n", + " resultado=a+b+c\n", + " return resultado\n", + "\n", + "summation3(3,8,16)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# print summation3" + "print(summation3)" ] }, { @@ -125,7 +191,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -134,23 +200,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "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:" + " \n", + " # Your code here:\n", + " i=0\n", + " resultado=sum(v for k,v in kwargs.items() if k!='red')\n", + " \n", + " return resultado" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "54" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# print summation4" + "summation4(**dictionary)" ] }, { @@ -162,36 +243,70 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a=4\n", "b=6\n", "c=15\n", "d=[48, 465, 23, 96]\n", - "e={'A':16, 'B':32, 'C':64}" + "e={'A':16, 'B':32, 'C':64}\n", + "#dict[a,b,c,d,e]\n", + "type(e)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 157, "metadata": {}, "outputs": [], "source": [ - "def summation5('define the function input'):\n", + "def summation5(a,b,c,*d,**e):\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:" + " # Your code here:\n", + " \n", + " d=sum(i for i in d if d)\n", + " e=sum(v for k,v in e.items())\n", + " resultado=a+b+c+d+e\n", + " return resultado\n", + " \n", + " \n", + " \n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 161, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "769" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# print summation5" + "summation5(a,b,c,*d,**e)\n", + "#summation5(14,b,c,*d,**{'A':16, 'B':32, 'C':65})" ] }, { @@ -205,9 +320,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 164, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], "source": [ "# We first define our iterator:\n", "\n", @@ -220,9 +343,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 165, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "# We continue to iterate through the iterator.\n", "\n", @@ -231,18 +362,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], "source": [ "print(next(iterator))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 167, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "ename": "StopIteration", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", + "Input \u001b[1;32mIn [167]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# After we have iterated through all elements, we will get a StopIteration Error\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43miterator\u001b[49m\u001b[43m)\u001b[49m)\n", + "\u001b[1;31mStopIteration\u001b[0m: " + ] + } + ], "source": [ "# After we have iterated through all elements, we will get a StopIteration Error\n", "\n", @@ -251,9 +404,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 211, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n" + ] + } + ], "source": [ "# We can also iterate through an iterator using a for loop like this:\n", "# Note: we cannot go back directly in an iterator once we have traversed through the elements. \n", @@ -274,7 +437,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 207, "metadata": {}, "outputs": [], "source": [ @@ -288,16 +451,39 @@ " # Sample Input: iter([1,2,3])\n", " # Sample Output: 2\n", " \n", - " # Your code here:" + " # Your code here:\n", + " \n", + " #for i in iterator:\n", + " # if i%2==0:\n", + " # print(\"output: \", i)\n", + " # else:\n", + " # print(\"no es divisible por 2\")\n", + " for i in iterator:\n", + " if i%2==0:\n", + " print(i)\n", + " else:\n", + " print(\"0\")\n", + " return" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 208, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "0\n", + "None\n" + ] + } + ], "source": [ - "# print divisible2" + "print(divisible2(iterator))" ] }, { @@ -311,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 212, "metadata": {}, "outputs": [], "source": [ @@ -331,9 +517,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 213, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], "source": [ "iterator = firstn(5)\n", "\n", @@ -350,7 +548,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 256, "metadata": {}, "outputs": [], "source": [ @@ -360,16 +558,54 @@ " # Output: iterator\n", " \n", " # Sample Input: 5\n", - " # Sample Output: iter([0, 2, 4])" + " # Sample Output: iter([0, 2, 4])\n", + " \n", + " for i in range(n):\n", + " yield i%2==0\n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 261, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(even_iterator(5))" + ] + }, + { + "cell_type": "code", + "execution_count": 258, "metadata": {}, "outputs": [], "source": [ - "# print even_iterator" + "number=even_iterator(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 259, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(number)" ] }, { @@ -382,7 +618,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -396,7 +632,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.10.3" } }, "nbformat": 4, diff --git a/your-code/main.ipynb b/your-code/main[Moises_Vargas].ipynb similarity index 56% rename from your-code/main.ipynb rename to your-code/main[Moises_Vargas].ipynb index d68aeb6..0fe428d 100644 --- a/your-code/main.ipynb +++ b/your-code/main[Moises_Vargas].ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -30,23 +30,46 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2926\n" + ] + } + ], "source": [ "def summation(num):\n", " # This function returns 1+2+3+....+num\n", - " \n", - " # Your code here: " + " resultado=sum(i for i in range(1, num+1))\n", + " return resultado\n", + " # Your code here: \n", + "\n", + "print(summation(num)) " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2926" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# print summation" + "# print summation\n", + "summation(num)" ] }, { @@ -60,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -69,23 +92,43 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "27" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def summation2(*args):\n", - " # This function returns the sum of *args\n", - " \n", - " # Your code here:" + " resultado=sum(i for i in array)\n", + " return resultado\n", + "summation2(array)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27\n" + ] + } + ], "source": [ - "# print summation2" + "# print summation2\n", + "print(summation2(array))" ] }, { @@ -97,23 +140,46 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "27" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def summation3(a, b, c):\n", " # This function returns a+b+c\n", - " \n", - " # Your code here:" + " \n", + " # Your code here:\n", + " resultado=a+b+c\n", + " return resultado\n", + "\n", + "summation3(3,8,16)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# print summation3" + "print(summation3)" ] }, { @@ -125,7 +191,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -134,23 +200,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "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:" + " \n", + " # Your code here:\n", + " i=0\n", + " resultado=sum(v for k,v in kwargs.items() if k!='red')\n", + " \n", + " return resultado" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "54" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# print summation4" + "summation4(**dictionary)" ] }, { @@ -162,36 +243,70 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a=4\n", "b=6\n", "c=15\n", "d=[48, 465, 23, 96]\n", - "e={'A':16, 'B':32, 'C':64}" + "e={'A':16, 'B':32, 'C':64}\n", + "#dict[a,b,c,d,e]\n", + "type(e)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 157, "metadata": {}, "outputs": [], "source": [ - "def summation5('define the function input'):\n", + "def summation5(a,b,c,*d,**e):\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:" + " # Your code here:\n", + " \n", + " d=sum(i for i in d if d)\n", + " e=sum(v for k,v in e.items())\n", + " resultado=a+b+c+d+e\n", + " return resultado\n", + " \n", + " \n", + " \n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 161, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "769" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# print summation5" + "summation5(a,b,c,*d,**e)\n", + "#summation5(14,b,c,*d,**{'A':16, 'B':32, 'C':65})" ] }, { @@ -205,9 +320,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 164, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], "source": [ "# We first define our iterator:\n", "\n", @@ -220,9 +343,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 165, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "# We continue to iterate through the iterator.\n", "\n", @@ -231,18 +362,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], "source": [ "print(next(iterator))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 167, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "ename": "StopIteration", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", + "Input \u001b[1;32mIn [167]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# After we have iterated through all elements, we will get a StopIteration Error\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43miterator\u001b[49m\u001b[43m)\u001b[49m)\n", + "\u001b[1;31mStopIteration\u001b[0m: " + ] + } + ], "source": [ "# After we have iterated through all elements, we will get a StopIteration Error\n", "\n", @@ -251,9 +404,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 211, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n" + ] + } + ], "source": [ "# We can also iterate through an iterator using a for loop like this:\n", "# Note: we cannot go back directly in an iterator once we have traversed through the elements. \n", @@ -274,7 +437,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 207, "metadata": {}, "outputs": [], "source": [ @@ -288,16 +451,39 @@ " # Sample Input: iter([1,2,3])\n", " # Sample Output: 2\n", " \n", - " # Your code here:" + " # Your code here:\n", + " \n", + " #for i in iterator:\n", + " # if i%2==0:\n", + " # print(\"output: \", i)\n", + " # else:\n", + " # print(\"no es divisible por 2\")\n", + " for i in iterator:\n", + " if i%2==0:\n", + " print(i)\n", + " else:\n", + " print(\"0\")\n", + " return" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 208, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "0\n", + "None\n" + ] + } + ], "source": [ - "# print divisible2" + "print(divisible2(iterator))" ] }, { @@ -311,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 212, "metadata": {}, "outputs": [], "source": [ @@ -331,9 +517,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 213, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], "source": [ "iterator = firstn(5)\n", "\n", @@ -350,7 +548,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -360,18 +558,63 @@ " # Output: iterator\n", " \n", " # Sample Input: 5\n", - " # Sample Output: iter([0, 2, 4])" + " # Sample Output: iter([0, 2, 4])\n", + " \n", + " for i in range(0, n, 2):\n", + " yield i\n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(even_iterator(5))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ - "# print even_iterator" + "number=even_iterator(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(number)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -382,7 +625,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -396,7 +639,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.10.3" } }, "nbformat": 4,