Ejercicios realizados

parent 81c80bef
......@@ -774,10 +774,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"2\n",
"4\n",
"6\n",
"8\n",
"10\n",
"12\n",
"14\n",
"16\n",
"18\n",
"20\n"
]
}
],
"source": [
"for i in range(0,21,2):\n",
" print (i)"
]
},
{
"cell_type": "markdown",
......@@ -788,12 +809,26 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 2,
"metadata": {},
"outputs": [],
"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",
"\n"
"for i in range(len(A)):\n",
" if (A[i] > 10):\n",
" print (A[i])"
]
},
{
......@@ -805,12 +840,22 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 5, 8, 13]\n"
]
}
],
"source": [
"a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n",
"b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n"
"b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n",
"c = set(a) & set(b)\n",
"print(list(c))"
]
},
{
......@@ -822,12 +867,27 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"indica cuantos numeros quieres calcular:10\n",
"[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n"
]
}
],
"source": [
"def fibonacci(n):\n",
" pass"
" F = [1, 1]\n",
" for i in range(2, n):\n",
" F += [F[i-2] + F[i-1]]\n",
" print(F)\n",
"\n",
"numero = int( input(\"indica cuantos numeros quieres calcular:\") )\n",
"fibonacci(numero)"
]
},
{
......@@ -839,11 +899,26 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"La suma es: 20\n"
]
}
],
"source": [
"a = [8, 2, 3, 0, 7]"
"a = [8, 2, 3, 0, 7]\n",
"def suma(x):\n",
" S = 0\n",
" for i in range(len(x)):\n",
" S += x[i]\n",
" print('La suma es:', S)\n",
"\n",
"suma(a)"
]
},
{
......@@ -855,11 +930,37 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 4,
"metadata": {},
"outputs": [],
"output_type": "execute_result"
}
],
"source": [
"a = [1,2,2,3,3,3,3,4,5,5]"
"b = [1,2,2,3,3,3,3,4,5,5]\n",
"\n",
"def uni(a):\n",
" unico = [a[0]]\n",
" for i in range(len(a)):\n",
" for j in range(len(a)):\n",
" if i != j:\n",
" if a[i] != a[j]:\n",
" for k in range(len(unico)):\n",
" if a[j] == unico[k]:\n",
" break \n",
" elif k == len(unico)-1: \n",
" unico.append(a[j])\n",
" return unico\n",
"\n",
"uni(b)"
]
},
{
......@@ -874,22 +975,31 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Escribe un nuemero:8\n"
"Escribe un numero: 8128\n",
"El número 8128 ES perfecto\n"
]
}
],
"source": [
"def perfect(x):\n",
" pass\n",
"numero = input(\"Escribe un nuemero:\")\n",
"perfect(numero)"
"def perfect(n):\n",
" fact = [1]\n",
" for x in range(2,n):\n",
" if n % x == 0:\n",
" fact.append(x)\n",
" if sum(fact) == n:\n",
" print('El número', n, 'ES perfecto')\n",
" else:\n",
" print('El número', n, 'NO es perfecto')\n",
"\n",
"x = int(input(\"Escribe un numero: \"))\n",
"perfect(x)"
]
},
{
......@@ -904,14 +1014,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Numero de lineas para triangulo de Pascal: 7\n"
]
},
{
"data": {
"text/plain": [
"[[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",
" [1, 6, 15, 20, 15, 6, 1],\n",
" [1, 7, 21, 35, 35, 21, 7, 1]]"
]
},
"execution_count": 11,
"metadata": {},
"outputs": [],
"output_type": "execute_result"
}
],
"source": [
"def pascal(n):\n",
" pass\n",
"numero = input(\"Indica el numero de filas:\")\n",
"pascal(numero)"
"def trianguloPascal(n):\n",
" lista = [[1],[1,1]]\n",
" for i in range(1,n):\n",
" fila = [1]\n",
" for j in range(0,len(lista[i])-1):\n",
" fila.extend([ lista[i][j] + lista[i][j+1] ])\n",
" fila += [1]\n",
" lista.append(fila)\n",
" return lista\n",
"\n",
"n = int(input(\"Numero de lineas para triangulo de Pascal: \"))\n",
"trianguloPascal(n)"
]
},
{
......@@ -922,6 +1065,34 @@
"[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. "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Escribe una frase: The quick brown fox jumps over the lazy dog\n",
"La frase ES un Panagrama\n"
]
}
],
"source": [
"def esPanagrama(frase):\n",
" alfabeto = 'abcdefghijklmnopqrstuvwxyz'\n",
" for w in range(len(alfabeto)):\n",
" if alfabeto[w] not in frase:\n",
" print('La frase NO es un Panagrama')\n",
" break\n",
" else:\n",
" print('La frase ES un Panagrama')\n",
" \n",
"x = input('Escribe una frase: ')\n",
"esPanagrama(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -948,10 +1119,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"\n",
"22\n",
"\n",
"333\n",
"\n",
"4444\n",
"\n",
"55555\n",
"\n",
"666666\n",
"\n",
"7777777\n",
"\n",
"88888888\n",
"\n",
"999999999\n",
"\n"
]
}
],
"source": [
"for z in range(1, 10):\n",
" print(str(z) * z + '\\n')"
]
}
],
"metadata": {
......@@ -970,7 +1169,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.5.3"
}
},
"nbformat": 4,
......
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