Commit e3367e66 authored by geobumac's avatar geobumac

mejoras de codigo

parent abb0d2f2
......@@ -774,7 +774,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 28,
"metadata": {},
"outputs": [
{
......@@ -819,7 +819,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 29,
"metadata": {},
"outputs": [
{
......@@ -830,7 +830,8 @@
"21\n",
"34\n",
"55\n",
"89\n"
"89\n",
"[13, 21, 34, 55, 89]\n"
]
}
],
......@@ -839,9 +840,17 @@
"i=0\n",
"for i in A:\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",
"metadata": {},
......@@ -851,7 +860,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 30,
"metadata": {},
"outputs": [
{
......@@ -877,25 +886,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cuantos numeros de la secuancia Fibonacci quiere calcular:10\n",
"cuantos numeros de la secuancia Fibonacci quiere calcular:5\n",
"0\n",
"1\n",
"1\n",
"2\n",
"3\n",
"5\n",
"8\n",
"13\n",
"21\n",
"34\n",
"55\n"
"5\n"
]
}
],
......@@ -922,7 +926,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 32,
"metadata": {},
"outputs": [
{
......@@ -951,7 +955,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 34,
"metadata": {},
"outputs": [
{
......@@ -982,32 +986,45 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Escribe un nuemero:10000\n",
"10000 no es un numero perfecto\n"
"Escribe un nuemero:28\n",
"28 es un numero perfecto\n",
"28 es un numero perfecto\n"
]
}
],
"source": [
"from functools import reduce\n",
"def perfect(x):\n",
" suma = 0\n",
" for i in range(1,x):\n",
" if x % i == 0:\n",
" suma += i\n",
" \n",
" if x == suma:\n",
" print(\"%s es un numero perfecto\" % x)\n",
" else:\n",
" print(\"%s no es un numero perfecto\" % x)\n",
" \n",
" return suma\n",
"\n",
"def perfect2(x):\n",
" a = range(1,x)\n",
" suma = reduce((lambda x, y: x + y), list(filter(lambda i: x%i == 0, a)))\n",
" return suma\n",
" \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 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": null,
"metadata": {},
"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"
]
}
],
"outputs": [],
"source": [
"def pascal(n):\n",
" lista = [[1],[1,1]]\n",
......@@ -1065,19 +1068,9 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"False\n",
"True\n"
]
}
],
"outputs": [],
"source": [
"def panagrama(phrase):\n",
" alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n",
......@@ -1113,25 +1106,9 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {},
"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"
]
}
],
"outputs": [],
"source": [
"for i in range(1, 10):\n",
" aux = \"\"\n",
......@@ -1140,6 +1117,13 @@
" print(aux);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......@@ -1164,7 +1148,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.7"
}
},
"nbformat": 4,
......
......@@ -310,13 +310,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar']\n",
"pares [0, 2, 4, 6, 8]\n",
"impares [1, 3, 5, 7, 9]\n"
]
......@@ -324,8 +325,8 @@
],
"source": [
"a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"print(\"pares \", [i for i in a if i%2==0])\n",
"print(\"impares \", [i for i in a if i%2!=0])"
"b = list(map(lambda x: 'par'if x%2== 0 else 'impar', a))\n",
"print(b)"
]
},
{
......@@ -439,23 +440,23 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[22, 54, 62]"
"[5, 7, 97, 77, 23, 73, 61]"
]
},
"execution_count": 31,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"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 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -159,7 +159,7 @@
"range"
]
},
"execution_count": 2,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
......@@ -206,7 +206,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"metadata": {},
"outputs": [
{
......@@ -215,7 +215,7 @@
"dict"
]
},
"execution_count": 1,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -774,7 +774,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 28,
"metadata": {},
"outputs": [
{
......@@ -819,7 +819,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 29,
"metadata": {},
"outputs": [
{
......@@ -860,7 +860,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 30,
"metadata": {},
"outputs": [
{
......@@ -886,25 +886,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cuantos numeros de la secuancia Fibonacci quiere calcular:10\n",
"cuantos numeros de la secuancia Fibonacci quiere calcular:5\n",
"0\n",
"1\n",
"1\n",
"2\n",
"3\n",
"5\n",
"8\n",
"13\n",
"21\n",
"34\n",
"55\n"
"5\n"
]
}
],
......@@ -931,7 +926,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 32,
"metadata": {},
"outputs": [
{
......@@ -960,7 +955,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 34,
"metadata": {},
"outputs": [
{
......@@ -973,8 +968,6 @@
],
"source": [
"a = [1,2,2,3,3,3,3,4,5,5]\n",
"def test_printUnique()\n",
"\n",
"def printUnique(a):\n",
" print(list(set(a)))\n",
" \n",
......@@ -993,32 +986,45 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Escribe un nuemero:10000\n",
"10000 no es un numero perfecto\n"
"Escribe un nuemero:28\n",
"28 es un numero perfecto\n",
"28 es un numero perfecto\n"
]
}
],
"source": [
"from functools import reduce\n",
"def perfect(x):\n",
" suma = 0\n",
" for i in range(1,x):\n",
" if x % i == 0:\n",
" suma += i\n",
" \n",
" if x == suma:\n",
" print(\"%s es un numero perfecto\" % x)\n",
" else:\n",
" print(\"%s no es un numero perfecto\" % x)\n",
" \n",
" return suma\n",
"\n",
"def perfect2(x):\n",
" a = range(1,x)\n",
" suma = reduce((lambda x, y: x + y), list(filter(lambda i: x%i == 0, a)))\n",
" return suma\n",
" \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 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": null,
"metadata": {},
"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"
]
}
],
"outputs": [],
"source": [
"def pascal(n):\n",
" lista = [[1],[1,1]]\n",
......@@ -1076,19 +1068,9 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"False\n",
"True\n"
]
}
],
"outputs": [],
"source": [
"def panagrama(phrase):\n",
" alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n",
......@@ -1124,25 +1106,9 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {},
"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"
]
}
],
"outputs": [],
"source": [
"for i in range(1, 10):\n",
" aux = \"\"\n",
......@@ -1151,6 +1117,13 @@
" print(aux);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......
......@@ -310,13 +310,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar', 'par', 'impar']\n",
"pares [0, 2, 4, 6, 8]\n",
"impares [1, 3, 5, 7, 9]\n"
]
......@@ -324,8 +325,8 @@
],
"source": [
"a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"print(\"pares \", [i for i in a if i%2==0])\n",
"print(\"impares \", [i for i in a if i%2!=0])"
"b = list(map(lambda x: 'par'if x%2== 0 else 'impar', a))\n",
"print(b)"
]
},
{
......@@ -439,23 +440,23 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[22, 54, 62]"
"[5, 7, 97, 77, 23, 73, 61]"
]
},
"execution_count": 31,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"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