"Python fue creado en 1991 por Guido van Rossum, con la filosofia de crear codigo legible, por lo que la identacion es obligatoria. Su desarrollo esta administrado por **Python Software Foundation** (python.org).\n",
"Python fue creado en 1991 por Guido van Rossum, con la filosofia de crear codigo legible, por lo que la identacion es obligatoria. Su desarrollo esta administrado por **Python Software Foundation** (python.org).\n",
"\n",
"\n",
"\n",
"\n",
"Caracteristicas:\n",
"Caracteristicas:\n",
"* Alto Nivel\n",
"* Alto Nivel\n",
"* Interpretado (Se ejecuta sin compilación previa)\n",
"* Interpretado (Se ejecuta sin compilación previa)\n",
"* Tipificación Dinamica (Se realiza durante en tiempo de ejecución)\n",
"* Tipificación Dinamica (Se realiza durante en tiempo de ejecución)\n",
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
"int"
"int"
]
]
},
},
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -60,7 +60,7 @@
...
@@ -60,7 +60,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -69,7 +69,7 @@
...
@@ -69,7 +69,7 @@
"float"
"float"
]
]
},
},
"execution_count": 6,
"execution_count": 2,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -80,7 +80,7 @@
...
@@ -80,7 +80,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -89,7 +89,7 @@
...
@@ -89,7 +89,7 @@
"complex"
"complex"
]
]
},
},
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -110,7 +110,7 @@
...
@@ -110,7 +110,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -119,7 +119,7 @@
...
@@ -119,7 +119,7 @@
"list"
"list"
]
]
},
},
"execution_count": 9,
"execution_count": 4,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -130,7 +130,7 @@
...
@@ -130,7 +130,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 10,
"execution_count": 5,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -139,7 +139,7 @@
...
@@ -139,7 +139,7 @@
"tuple"
"tuple"
]
]
},
},
"execution_count": 10,
"execution_count": 5,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -150,7 +150,7 @@
...
@@ -150,7 +150,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 11,
"execution_count": 6,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -159,13 +159,13 @@
...
@@ -159,13 +159,13 @@
"range"
"range"
]
]
},
},
"execution_count": 11,
"execution_count": 6,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": [
"source": [
"type(range(1))"
"type(range(1))"
]
]
},
},
{
{
...
@@ -178,7 +178,7 @@
...
@@ -178,7 +178,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 13,
"execution_count": 7,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -187,7 +187,7 @@
...
@@ -187,7 +187,7 @@
"str"
"str"
]
]
},
},
"execution_count": 13,
"execution_count": 7,
"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": 15,
"execution_count": 8,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -215,7 +215,7 @@
...
@@ -215,7 +215,7 @@
"dict"
"dict"
]
]
},
},
"execution_count": 15,
"execution_count": 8,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -235,7 +235,7 @@
...
@@ -235,7 +235,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 34,
"execution_count": 9,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -244,7 +244,7 @@
...
@@ -244,7 +244,7 @@
"{1, 2, 3, 5, 6}"
"{1, 2, 3, 5, 6}"
]
]
},
},
"execution_count": 34,
"execution_count": 9,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -273,7 +273,7 @@
...
@@ -273,7 +273,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 16,
"execution_count": 10,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -282,7 +282,7 @@
...
@@ -282,7 +282,7 @@
"True"
"True"
]
]
},
},
"execution_count": 16,
"execution_count": 10,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -293,7 +293,7 @@
...
@@ -293,7 +293,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 18,
"execution_count": 11,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -302,7 +302,7 @@
...
@@ -302,7 +302,7 @@
"False"
"False"
]
]
},
},
"execution_count": 18,
"execution_count": 11,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -313,7 +313,7 @@
...
@@ -313,7 +313,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 19,
"execution_count": 12,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -322,7 +322,7 @@
...
@@ -322,7 +322,7 @@
"False"
"False"
]
]
},
},
"execution_count": 19,
"execution_count": 12,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -333,7 +333,7 @@
...
@@ -333,7 +333,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 17,
"execution_count": 13,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -342,7 +342,7 @@
...
@@ -342,7 +342,7 @@
"True"
"True"
]
]
},
},
"execution_count": 17,
"execution_count": 13,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -353,7 +353,7 @@
...
@@ -353,7 +353,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 22,
"execution_count": 14,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -362,7 +362,7 @@
...
@@ -362,7 +362,7 @@
"False"
"False"
]
]
},
},
"execution_count": 22,
"execution_count": 14,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -373,7 +373,7 @@
...
@@ -373,7 +373,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 23,
"execution_count": 15,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -382,7 +382,7 @@
...
@@ -382,7 +382,7 @@
"True"
"True"
]
]
},
},
"execution_count": 23,
"execution_count": 15,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
@@ -437,7 +437,7 @@
...
@@ -437,7 +437,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 36,
"execution_count": 16,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -457,7 +457,7 @@
...
@@ -457,7 +457,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 38,
"execution_count": 17,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -479,7 +479,7 @@
...
@@ -479,7 +479,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 42,
"execution_count": 18,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -499,7 +499,7 @@
...
@@ -499,7 +499,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 44,
"execution_count": 19,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -521,6 +521,99 @@
...
@@ -521,6 +521,99 @@
" print(i)"
" print(i)"
]
]
},
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"3\n",
"4\n"
]
}
],
"source": [
"for i in range(5):\n",
" if(i==2):\n",
" continue\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n"
]
}
],
"source": [
"for i in range(5):\n",
" if(i==2):\n",
" break\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n"
]
}
],
"source": [
"for i in range(5):\n",
" if(i==2):\n",
" pass\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.5\n",
"0.6666666666666666\n",
"1.0\n",
"2.0\n",
"ERROR\n"
]
}
],
"source": [
"for i in reversed(range(5)):\n",
" try:\n",
" print(2/i)\n",
" except:\n",
" print(\"ERROR\")\n"
]
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
...
@@ -535,31 +628,356 @@
...
@@ -535,31 +628,356 @@
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"# 1.4 Ejercicios\n",
"## 1.4 Funciones\n",
"## 1.4.1 Inprimir todos los numeros pares en 0 y 20."
"Una función es un conjunto de setencias que pueden ser invocadas varias veces durante la ejecución de un programa. Permiten minimizar el codigo, amuentar su legibilidad y permiten reutilizar código. En python las funciones son definida por la palabra reservada **def**. \n",
"\n"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
"source": []
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World\n"
]
}
],
"source": [
"def HelloWorld():\n",
" print(\"Hello World\")\n",
"\n",
"HelloWorld()\n"
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"## 1.4.2 Inprimir todos los numeros myores a 10 de la lista A"
"### 1.4.1 Parametros\n",
"La funciones pueden aceptar arguentos de entrada y devoler resultados."
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 7,
"execution_count": 25,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello Mario\n"
]
}
],
"source": [
"def Hello(name):\n",
" print(\"Hello \"+name)\n",
"Hello(\"Mario\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.4.2 Parametros Opcionales\n",
"Las funciones tampien pueden aceptar parametros opcionales, los cuales toman en valor indicado por defecto si no son pasados a la funcion."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello Mario!!!\n",
"Hello Mario?\n",
"Hello Mario!\n",
"Hello Alex!!\n"
]
},
{
"data": {
"text/plain": [
"[1]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def Hello(name, x=\"!!!\"):\n",
" print(\"Hello \" + name + x)\n",
"Hello(\"Mario\")\n",
"Hello(\"Mario\",\"?\")\n",
"Hello(x=\"!\", name=\"Mario\")\n",
"p = {\"name\":\"Alex\", \"x\":\"!!\"}\n",
"Hello(**p)\n",
"[1,]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.4.3 Desempaquetado"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 1 2\n",
"0 4 5\n",
"[6, 7, 8] 1 2\n",
"6 7 8\n",
"{'a': 9, 'b': 10, 'c': 11} 1 2\n",
"9 10 11\n"
]
}
],
"source": [
"def unpack(a,b=1,c=2):\n",
" print(a,b,c)\n",
"\n",
"l = [6,7,8] \n",
"d = {\"a\":9,\"b\":10,\"c\":11} \n",
"unpack(0)\n",
"unpack(0, 4, 5)\n",
"unpack(l)\n",
"unpack(*l)\n",
"unpack(d)\n",
"unpack(**d)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.5 Ejercicios\n",
"### 1.5.1 Imprimir todos los numeros pares entre 0 y 20 usando *for* o *while*."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n",
"4\n",
"6\n",
"8\n",
"10\n",
"12\n",
"14\n",
"16\n",
"18\n",
"20\n"
]
}
],
"source": [
"i = 0\n",
"while i < 20:\n",
" i+=2\n",
" print(i)\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.2 Imprimir todos los numeros mayores a 10 de la lista A"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\n",
"21\n",
"34\n",
"55\n",
"89\n"
]
}
],
"source": [
"A = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] \n",
"for x in A:\n",
" if(x > 10): \n",
" print (x)\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.3 Dadas dos listas A y B, obten una lista con sus elementos comunes (A∩B)."
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{1, 2, 3, 5, 8, 13}\n"
]
}
],
"source": [
"a = set ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89])\n",
"### 1.5.4 Pregunta al usario cuantos numeros de la secuancia Fibonacci quiere calcular y escribe una funcion que calcule la secuencia e imprima el resultado."
]
},
{
"cell_type": "code",
"execution_count": 160,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cuantos numeros de Fibonacci desea:\n",
"10\n",
"[1]\n",
"[1, 1]\n",
"[1, 1, 2]\n",
"[1, 1, 2, 3]\n",
"[1, 1, 2, 3, 5]\n",
"[1, 1, 2, 3, 5, 8]\n",
"[1, 1, 2, 3, 5, 8, 13]\n",
"[1, 1, 2, 3, 5, 8, 13, 21]\n",
"[1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
"[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n"
]
}
],
"source": [
"def fibonacci(n):\n",
" pass\n",
"a = 0\n",
"b = 1\n",
"fib = []\n",
"\n",
"print (\"Cuantos numeros de Fibonacci desea:\")\n",
"n = int (input())\n",
"\n",
"i = 0\n",
"while i < n:\n",
" fib.append(b)\n",
" c = a+b\n",
" a = b\n",
" b = c\n",
" i +=1\n",
" print (fib)\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.5 Escribe una funcion que sume todos los uneros en una lista."
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n"
]
}
],
"source": [
"a = [8, 2, 3, 0, 7]\n",
"def suma(a):\n",
" cuenta = 0\n",
" for i in a:\n",
" cuenta = cuenta +i\n",
" return cuenta\n",
"\n",
"print( suma (a))\n",
"\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.6 Escribe una funcion que tome una lista y regrese los elementos unicos en la lista.\n"
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{1, 2, 3, 4, 5}\n"
]
}
],
"source": [
"source": [
"A = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n",
"a = [1,2,2,3,3,3,3,4,5,5]\n",
"b = set(a)\n",
"print (b)\n",
"\n",
"\n"
"\n"
]
]
},
},
...
@@ -567,41 +985,144 @@
...
@@ -567,41 +985,144 @@
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"## 1.4.3 Dadas dos listas A y B, obten una lista con los elementos comunes a las dos listas (A∩B)."
"1.5.7 Escribe una funcion que indique si un numero es o no perfecto.\n",
"[Wikipedia:](https://es.wikipedia.org/wiki/N%C3%BAmero_perfecto) *Un número perfecto es un número natural que es igual a la suma de sus divisores propios positivos. Dicho de otra forma, un número perfecto es aquel que es amigo de sí mismo.\n",
"Así, 6 es un número perfecto porque sus divisores propios son 1, 2 y 3; y 6 = 1 + 2 + 3. Los siguientes números perfectos son 28, 496 y 8128.*\n",
"El triángulo de Pascal es un triángulo numérico con números dispuestos en filas escalonadas de manera tal que:\n",
"$a_{nr}=\\frac{n!}{r!(n-r)!}=\\binom{n}{r}$\n"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ingrese el valor de n:3\n",
"1\n",
"\n",
"\n",
"1\n",
"1.0\n",
"\n",
"\n",
"1\n",
"2.0\n",
"1.0\n",
"\n",
"\n",
"1\n",
"3.0\n",
"3.0\n",
"1.0\n",
"\n",
"\n",
"\n"
"\n"
]
]
}
],
"source": [
"n = int( input(\"ingrese el valor de n:\"))\n",
"\n",
"for i in range (0, n+1):\n",
" n = 1\n",
"\n",
" for j in range(0, i+1):\n",
" print( str(n) + \"\")\n",
" n = n * ( i - j ) / (j + 1)\n",
"\n",
" print(\"\\n\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.9 Escribe una funcion que indique si una frase es un panagrama.\n",
"[Wikipedia](https://es.wikipedia.org/wiki/Pangrama):Un pangrama (del griego: παν γραμμα, «todas las letras») o frase holoalfabética es un texto que usa todas las letras posibles del alfabeto de un idioma. \n",
" \n",
" \n",
" \n"
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"source": [
"x = input('What is your name?: ')\n",
"### 1.5.10 Escribe un programa que imprima el siguiente un **for** anidado.\n",
"Python fue creado en 1991 por Guido van Rossum, con la filosofia de crear codigo legible, por lo que la identacion es obligatoria. Su desarrollo esta administrado por **Python Software Foundation** (python.org).\n",
"Python fue creado en 1991 por Guido van Rossum, con la filosofia de crear codigo legible, por lo que la identacion es obligatoria. Su desarrollo esta administrado por **Python Software Foundation** (python.org).\n",
"\n",
"\n",
"\n",
"\n",
"Caracteristicas:\n",
"Caracteristicas:\n",
"* Alto Nivel\n",
"* Alto Nivel\n",
"* Interpretado (Se ejecuta sin compilación previa)\n",
"* Interpretado (Se ejecuta sin compilación previa)\n",
"* Tipificación Dinamica (Se realiza durante en tiempo de ejecución)\n",
"* Tipificación Dinamica (Se realiza durante en tiempo de ejecución)\n",
...
@@ -774,10 +774,34 @@
...
@@ -774,10 +774,34 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
"source": []
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n",
"4\n",
"6\n",
"8\n",
"10\n",
"12\n",
"14\n",
"16\n",
"18\n",
"20\n"
]
}
],
"source": [
"i = 0\n",
"while i < 20:\n",
" i+=2\n",
" print(i)\n",
" \n",
" "
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
...
@@ -788,12 +812,28 @@
...
@@ -788,12 +812,28 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 28,
"execution_count": 80,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\n",
"21\n",
"34\n",
"55\n",
"89\n"
]
}
],
"source": [
"source": [
"A = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n",
"A = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] \n",
"\n"
"for x in A:\n",
" if(x > 10): \n",
" print (x)\n",
" \n",
" "
]
]
},
},
{
{
...
@@ -805,12 +845,25 @@
...
@@ -805,12 +845,25 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 29,
"execution_count": 125,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{1, 2, 3, 5, 8, 13}\n"
]
}
],
"source": [
"source": [
"a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n",
"a = set ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89])\n",
"print (\"Cuantos numeros de Fibonacci desea:\")\n",
"n = int (input())\n",
"\n",
"i = 0\n",
"while i < n:\n",
" fib.append(b)\n",
" c = a+b\n",
" a = b\n",
" b = c\n",
" i +=1\n",
" print (fib)\n",
" "
]
]
},
},
{
{
...
@@ -839,11 +927,28 @@
...
@@ -839,11 +927,28 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 31,
"execution_count": 110,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n"
]
}
],
"source": [
"source": [
"a = [8, 2, 3, 0, 7]"
"a = [8, 2, 3, 0, 7]\n",
"def suma(a):\n",
" cuenta = 0\n",
" for i in a:\n",
" cuenta = cuenta +i\n",
" return cuenta\n",
"\n",
"print( suma (a))\n",
"\n",
" "
]
]
},
},
{
{
...
@@ -855,18 +960,32 @@
...
@@ -855,18 +960,32 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 32,
"execution_count": 117,
"metadata": {},
"metadata": {
"outputs": [],
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{1, 2, 3, 4, 5}\n"
]
}
],
"source": [
"source": [
"a = [1,2,2,3,3,3,3,4,5,5]"
"a = [1,2,2,3,3,3,3,4,5,5]\n",
"b = set(a)\n",
"print (b)\n",
"\n",
"\n"
]
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### 1.5.7 Escribe una funcion que indique si un numero es o no perfecto.\n",
"1.5.7 Escribe una funcion que indique si un numero es o no perfecto.\n",
"[Wikipedia:](https://es.wikipedia.org/wiki/N%C3%BAmero_perfecto) *Un número perfecto es un número natural que es igual a la suma de sus divisores propios positivos. Dicho de otra forma, un número perfecto es aquel que es amigo de sí mismo.\n",
"[Wikipedia:](https://es.wikipedia.org/wiki/N%C3%BAmero_perfecto) *Un número perfecto es un número natural que es igual a la suma de sus divisores propios positivos. Dicho de otra forma, un número perfecto es aquel que es amigo de sí mismo.\n",
"Así, 6 es un número perfecto porque sus divisores propios son 1, 2 y 3; y 6 = 1 + 2 + 3. Los siguientes números perfectos son 28, 496 y 8128.*\n",
"Así, 6 es un número perfecto porque sus divisores propios son 1, 2 y 3; y 6 = 1 + 2 + 3. Los siguientes números perfectos son 28, 496 y 8128.*\n",
"\n"
"\n"
...
@@ -874,22 +993,40 @@
...
@@ -874,22 +993,40 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 34,
"execution_count": 26,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"Escribe un nuemero:8\n"
"Numero a comprobar:99999999\n",
"El 99999999 , NO es perfecto \n"
]
]
}
}
],
],
"source": [
"source": [
"def perfect(x):\n",
"def NP(x):\n",
" pass\n",
" suma = 0\n",
"numero = input(\"Escribe un nuemero:\")\n",
" for i in range(1,x):\n",
"perfect(numero)"
" if (x % i == 0):\n",
" suma += i\n",
" \n",
" if x == suma:\n",
"\n",
" return True\n",
"\n",
" else:\n",
"\n",
" return False\n",
"\n",
"x = int(input(\"Numero a comprobar:\"))\n",
"\n",
"if NP(x):\n",
" print(\"El %s es perfecto\" % x)\n",
"else:\n",
" \n",
" print(\"El %s , NO es perfecto \" % x)"
]
]
},
},
{
{
...
@@ -904,14 +1041,46 @@
...
@@ -904,14 +1041,46 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ingrese el valor de n:3\n",
"1\n",
"\n",
"\n",
"1\n",
"1.0\n",
"\n",
"\n",
"1\n",
"2.0\n",
"1.0\n",
"\n",
"\n",
"1\n",
"3.0\n",
"3.0\n",
"1.0\n",
"\n",
"\n"
]
}
],
"source": [
"source": [
"def pascal(n):\n",
"n = int( input(\"ingrese el valor de n:\"))\n",
" pass\n",
"\n",
"numero = input(\"Indica el numero de filas:\")\n",
"for i in range (0, n+1):\n",
"pascal(numero)"
" n = 1\n",
"\n",
" for j in range(0, i+1):\n",
" print( str(n) + \"\")\n",
" n = n * ( i - j ) / (j + 1)\n",
"\n",
" print(\"\\n\")"
]
]
},
},
{
{
...
@@ -919,9 +1088,19 @@
...
@@ -919,9 +1088,19 @@
"metadata": {},
"metadata": {},
"source": [
"source": [
"### 1.5.9 Escribe una funcion que indique si una frase es un panagrama.\n",
"### 1.5.9 Escribe una funcion que indique si una frase es un panagrama.\n",
"[Wikipedia](https://es.wikipedia.org/wiki/Pangrama):Un pangrama (del griego: παν γραμμα, «todas las letras») o frase holoalfabética es un texto que usa todas las letras posibles del alfabeto de un idioma. "
"[Wikipedia](https://es.wikipedia.org/wiki/Pangrama):Un pangrama (del griego: παν γραμμα, «todas las letras») o frase holoalfabética es un texto que usa todas las letras posibles del alfabeto de un idioma. \n",