Commit e3367e66 authored by geobumac's avatar geobumac

mejoras de codigo

parent abb0d2f2
...@@ -774,7 +774,7 @@ ...@@ -774,7 +774,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -819,7 +819,7 @@ ...@@ -819,7 +819,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -830,7 +830,8 @@ ...@@ -830,7 +830,8 @@
"21\n", "21\n",
"34\n", "34\n",
"55\n", "55\n",
"89\n" "89\n",
"[13, 21, 34, 55, 89]\n"
] ]
} }
], ],
...@@ -839,9 +840,17 @@ ...@@ -839,9 +840,17 @@
"i=0\n", "i=0\n",
"for i in A:\n", "for i in A:\n",
" if i > 10:\n", " if i > 10:\n",
" print(i)" " print(i)\n",
"print([i for i in A if i>10])"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -851,7 +860,7 @@ ...@@ -851,7 +860,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -877,25 +886,20 @@ ...@@ -877,25 +886,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"cuantos numeros de la secuancia Fibonacci quiere calcular:10\n", "cuantos numeros de la secuancia Fibonacci quiere calcular:5\n",
"0\n", "0\n",
"1\n", "1\n",
"1\n", "1\n",
"2\n", "2\n",
"3\n", "3\n",
"5\n", "5\n"
"8\n",
"13\n",
"21\n",
"34\n",
"55\n"
] ]
} }
], ],
...@@ -922,7 +926,7 @@ ...@@ -922,7 +926,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -951,7 +955,7 @@ ...@@ -951,7 +955,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -982,32 +986,45 @@ ...@@ -982,32 +986,45 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Escribe un nuemero:10000\n", "Escribe un nuemero:28\n",
"10000 no es un numero perfecto\n" "28 es un numero perfecto\n",
"28 es un numero perfecto\n"
] ]
} }
], ],
"source": [ "source": [
"from functools import reduce\n",
"def perfect(x):\n", "def perfect(x):\n",
" suma = 0\n", " suma = 0\n",
" for i in range(1,x):\n", " for i in range(1,x):\n",
" if x % i == 0:\n", " if x % i == 0:\n",
" suma += i\n", " suma += i\n",
" \n", " return suma\n",
" if x == suma:\n", "\n",
" print(\"%s es un numero perfecto\" % x)\n", "def perfect2(x):\n",
" else:\n", " a = range(1,x)\n",
" print(\"%s no es un numero perfecto\" % x)\n", " suma = reduce((lambda x, y: x + y), list(filter(lambda i: x%i == 0, a)))\n",
" return suma\n",
" \n", " \n",
"numero = int(input(\"Escribe un nuemero:\"))\n", "numero = int(input(\"Escribe un nuemero:\"))\n",
"perfect(numero)" "sum1 = perfect(numero)\n",
"sum2 = perfect2(numero)\n",
"\n",
"if numero == sum1:\n",
" print(\"%s es un numero perfecto\" % numero)\n",
"else:\n",
" print(\"%s no es un numero perfecto\" % numero)\n",
"if numero == sum2:\n",
" print(\"%s es un numero perfecto\" % numero)\n",
"else:\n",
" print(\"%s no es un numero perfecto\" % numero)"
] ]
}, },
{ {
...@@ -1022,23 +1039,9 @@ ...@@ -1022,23 +1039,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Indica el numero de filas:5\n",
"[1]\n",
"[1, 1]\n",
"[1, 2, 1]\n",
"[1, 3, 3, 1]\n",
"[1, 4, 6, 4, 1]\n",
"[1, 5, 10, 10, 5, 1]\n"
]
}
],
"source": [ "source": [
"def pascal(n):\n", "def pascal(n):\n",
" lista = [[1],[1,1]]\n", " lista = [[1],[1,1]]\n",
...@@ -1065,19 +1068,9 @@ ...@@ -1065,19 +1068,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"False\n",
"True\n"
]
}
],
"source": [ "source": [
"def panagrama(phrase):\n", "def panagrama(phrase):\n",
" alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n", " alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n",
...@@ -1113,25 +1106,9 @@ ...@@ -1113,25 +1106,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"22\n",
"333\n",
"4444\n",
"55555\n",
"666666\n",
"7777777\n",
"88888888\n",
"999999999\n"
]
}
],
"source": [ "source": [
"for i in range(1, 10):\n", "for i in range(1, 10):\n",
" aux = \"\"\n", " aux = \"\"\n",
...@@ -1140,6 +1117,13 @@ ...@@ -1140,6 +1117,13 @@
" print(aux);" " print(aux);"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
...@@ -1164,7 +1148,7 @@ ...@@ -1164,7 +1148,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2" "version": "3.6.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -310,13 +310,14 @@ ...@@ -310,13 +310,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"['par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar']\n",
"pares [0, 2, 4, 6, 8]\n", "pares [0, 2, 4, 6, 8]\n",
"impares [1, 3, 5, 7, 9]\n" "impares [1, 3, 5, 7, 9]\n"
] ]
...@@ -324,8 +325,8 @@ ...@@ -324,8 +325,8 @@
], ],
"source": [ "source": [
"a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", "a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"print(\"pares \", [i for i in a if i%2==0])\n", "b = list(map(lambda x: 'par'if x%2== 0 else 'impar', a))\n",
"print(\"impares \", [i for i in a if i%2!=0])" "print(b)"
] ]
}, },
{ {
...@@ -439,23 +440,23 @@ ...@@ -439,23 +440,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[22, 54, 62]" "[5, 7, 97, 77, 23, 73, 61]"
] ]
}, },
"execution_count": 31, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]\n", "a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]\n",
"list(filter(lambda x:x%2 == 0, a))" "list(filter(lambda x:x%2 != 0, a))"
] ]
}, },
{ {
......
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
"range" "range"
] ]
}, },
"execution_count": 2, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -215,7 +215,7 @@ ...@@ -215,7 +215,7 @@
"dict" "dict"
] ]
}, },
"execution_count": 1, "execution_count": 8,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -774,7 +774,7 @@ ...@@ -774,7 +774,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -819,7 +819,7 @@ ...@@ -819,7 +819,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -860,7 +860,7 @@ ...@@ -860,7 +860,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -886,25 +886,20 @@ ...@@ -886,25 +886,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"cuantos numeros de la secuancia Fibonacci quiere calcular:10\n", "cuantos numeros de la secuancia Fibonacci quiere calcular:5\n",
"0\n", "0\n",
"1\n", "1\n",
"1\n", "1\n",
"2\n", "2\n",
"3\n", "3\n",
"5\n", "5\n"
"8\n",
"13\n",
"21\n",
"34\n",
"55\n"
] ]
} }
], ],
...@@ -931,7 +926,7 @@ ...@@ -931,7 +926,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -960,7 +955,7 @@ ...@@ -960,7 +955,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -973,8 +968,6 @@ ...@@ -973,8 +968,6 @@
], ],
"source": [ "source": [
"a = [1,2,2,3,3,3,3,4,5,5]\n", "a = [1,2,2,3,3,3,3,4,5,5]\n",
"def test_printUnique()\n",
"\n",
"def printUnique(a):\n", "def printUnique(a):\n",
" print(list(set(a)))\n", " print(list(set(a)))\n",
" \n", " \n",
...@@ -993,32 +986,45 @@ ...@@ -993,32 +986,45 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Escribe un nuemero:10000\n", "Escribe un nuemero:28\n",
"10000 no es un numero perfecto\n" "28 es un numero perfecto\n",
"28 es un numero perfecto\n"
] ]
} }
], ],
"source": [ "source": [
"from functools import reduce\n",
"def perfect(x):\n", "def perfect(x):\n",
" suma = 0\n", " suma = 0\n",
" for i in range(1,x):\n", " for i in range(1,x):\n",
" if x % i == 0:\n", " if x % i == 0:\n",
" suma += i\n", " suma += i\n",
" \n", " return suma\n",
" if x == suma:\n", "\n",
" print(\"%s es un numero perfecto\" % x)\n", "def perfect2(x):\n",
" else:\n", " a = range(1,x)\n",
" print(\"%s no es un numero perfecto\" % x)\n", " suma = reduce((lambda x, y: x + y), list(filter(lambda i: x%i == 0, a)))\n",
" return suma\n",
" \n", " \n",
"numero = int(input(\"Escribe un nuemero:\"))\n", "numero = int(input(\"Escribe un nuemero:\"))\n",
"perfect(numero)" "sum1 = perfect(numero)\n",
"sum2 = perfect2(numero)\n",
"\n",
"if numero == sum1:\n",
" print(\"%s es un numero perfecto\" % numero)\n",
"else:\n",
" print(\"%s no es un numero perfecto\" % numero)\n",
"if numero == sum2:\n",
" print(\"%s es un numero perfecto\" % numero)\n",
"else:\n",
" print(\"%s no es un numero perfecto\" % numero)"
] ]
}, },
{ {
...@@ -1033,23 +1039,9 @@ ...@@ -1033,23 +1039,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Indica el numero de filas:5\n",
"[1]\n",
"[1, 1]\n",
"[1, 2, 1]\n",
"[1, 3, 3, 1]\n",
"[1, 4, 6, 4, 1]\n",
"[1, 5, 10, 10, 5, 1]\n"
]
}
],
"source": [ "source": [
"def pascal(n):\n", "def pascal(n):\n",
" lista = [[1],[1,1]]\n", " lista = [[1],[1,1]]\n",
...@@ -1076,19 +1068,9 @@ ...@@ -1076,19 +1068,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"False\n",
"True\n"
]
}
],
"source": [ "source": [
"def panagrama(phrase):\n", "def panagrama(phrase):\n",
" alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n", " alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n",
...@@ -1124,25 +1106,9 @@ ...@@ -1124,25 +1106,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"22\n",
"333\n",
"4444\n",
"55555\n",
"666666\n",
"7777777\n",
"88888888\n",
"999999999\n"
]
}
],
"source": [ "source": [
"for i in range(1, 10):\n", "for i in range(1, 10):\n",
" aux = \"\"\n", " aux = \"\"\n",
...@@ -1151,6 +1117,13 @@ ...@@ -1151,6 +1117,13 @@
" print(aux);" " print(aux);"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
...@@ -310,13 +310,14 @@ ...@@ -310,13 +310,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"['par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar']\n",
"pares [0, 2, 4, 6, 8]\n", "pares [0, 2, 4, 6, 8]\n",
"impares [1, 3, 5, 7, 9]\n" "impares [1, 3, 5, 7, 9]\n"
] ]
...@@ -324,8 +325,8 @@ ...@@ -324,8 +325,8 @@
], ],
"source": [ "source": [
"a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", "a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"print(\"pares \", [i for i in a if i%2==0])\n", "b = list(map(lambda x: 'par'if x%2== 0 else 'impar', a))\n",
"print(\"impares \", [i for i in a if i%2!=0])" "print(b)"
] ]
}, },
{ {
...@@ -439,23 +440,23 @@ ...@@ -439,23 +440,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[22, 54, 62]" "[5, 7, 97, 77, 23, 73, 61]"
] ]
}, },
"execution_count": 31, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]\n", "a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]\n",
"list(filter(lambda x:x%2 == 0, a))" "list(filter(lambda x:x%2 != 0, a))"
] ]
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment