Ejercicios realizados

parent 81c80bef
...@@ -774,10 +774,31 @@ ...@@ -774,10 +774,31 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
"source": [] {
"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", "cell_type": "markdown",
...@@ -788,12 +809,26 @@ ...@@ -788,12 +809,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 2,
"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 i in range(len(A)):\n",
" if (A[i] > 10):\n",
" print (A[i])"
] ]
}, },
{ {
...@@ -805,12 +840,22 @@ ...@@ -805,12 +840,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 3,
"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 = [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 @@ ...@@ -822,12 +867,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 4,
"metadata": {}, "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": [ "source": [
"def fibonacci(n):\n", "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 @@ ...@@ -839,11 +899,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"La suma es: 20\n"
]
}
],
"source": [ "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 @@ ...@@ -855,11 +930,37 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "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 @@ ...@@ -874,22 +975,31 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Escribe un nuemero:8\n" "Escribe un numero: 8128\n",
"El número 8128 ES perfecto\n"
] ]
} }
], ],
"source": [ "source": [
"def perfect(x):\n", "def perfect(n):\n",
" pass\n", " fact = [1]\n",
"numero = input(\"Escribe un nuemero:\")\n", " for x in range(2,n):\n",
"perfect(numero)" " 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 @@ ...@@ -904,14 +1014,47 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "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": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"def pascal(n):\n", "def trianguloPascal(n):\n",
" pass\n", " lista = [[1],[1,1]]\n",
"numero = input(\"Indica el numero de filas:\")\n", " for i in range(1,n):\n",
"pascal(numero)" " 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 @@ ...@@ -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. " "[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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -948,10 +1119,38 @@ ...@@ -948,10 +1119,38 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
"source": [] {
"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": { "metadata": {
...@@ -970,7 +1169,7 @@ ...@@ -970,7 +1169,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2" "version": "3.5.3"
} }
}, },
"nbformat": 4, "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