Commit efa8d9df authored by Gaspar's avatar Gaspar

Cambios iniciales

parent 205c898a
...@@ -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,73 +628,399 @@ ...@@ -535,73 +628,399 @@
"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": [ "source": [
"A = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n", "def Hello(name):\n",
"\n" " print(\"Hello \"+name)\n",
"Hello(\"Mario\")"
] ]
}, },
{ {
"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.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", "cell_type": "code",
"execution_count": 8, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "NameError", "name": "stdout",
"evalue": "name 'raw_input' is not defined", "output_type": "stream",
"output_type": "error", "text": [
"traceback": [ "Hello Mario!!!\n",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "Hello Mario?\n",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Hello Mario!\n",
"\u001b[0;32m<ipython-input-8-504d5d148c52>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnum\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Choose a number: \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "Hello Alex!!\n"
"\u001b[0;31mNameError\u001b[0m: name 'raw_input' is not defined" ]
},
{
"data": {
"text/plain": [
"[1]"
] ]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"num = int(raw_input(\"Choose a number: \"))\n", "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", "\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": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n",
"11\n",
"12\n",
"13\n",
"14\n",
"15\n",
"16\n",
"17\n",
"18\n",
"19\n",
"20\n"
]
}
],
"source": [
"for i in range(21):\n",
" print(i)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.2 Imprimir todos los numeros mayores a 10 de la lista A"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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",
"i=0\n",
"for i in A:\n",
" if i > 10:\n",
" print(i)"
]
},
{
"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": 14,
"metadata": {},
"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",
"print(set(a) & set(b))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 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": 30,
"metadata": {},
"outputs": [],
"source": [
"def fibonacci(n):\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.5 Escribe una funcion que sume todos los uneros en una lista."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n"
]
}
],
"source": [
"a = [8, 2, 3, 0, 7]\n",
"\n", "\n",
"def sumList(lista):\n",
" print(sum(lista))\n",
" \n",
"sumList(a)"
]
},
{
"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": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5]\n"
]
}
],
"source": [
"a = [1,2,2,3,3,3,3,4,5,5]\n",
"print(list(set(a)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 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",
"\n" "\n"
] ]
}, },
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Escribe un nuemero:8\n"
]
}
],
"source": [
"def perfect(x):\n",
" pass\n",
"numero = input(\"Escribe un nuemero:\")\n",
"perfect(numero)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.8 Escribe una funcion que imprima las prieras *n* filas del triangulo de Pascal.\n",
"[Wolfram](http://mathworld.wolfram.com/PascalsTriangle.html):\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", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = input('What is your name?: ')\n", "def pascal(n):\n",
"\n" " pass\n",
"numero = input(\"Indica el numero de filas:\")\n",
"pascal(numero)"
]
},
{
"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. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.5.10 Escribe un programa que imprima el siguiente un **for** anidado.\n",
"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"
] ]
}, },
{ {
...@@ -628,7 +1047,7 @@ ...@@ -628,7 +1047,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.3" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -774,10 +774,41 @@ ...@@ -774,10 +774,41 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
"source": [] {
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n",
"11\n",
"12\n",
"13\n",
"14\n",
"15\n",
"16\n",
"17\n",
"18\n",
"19\n",
"20\n"
]
}
],
"source": [
"for i in range(21):\n",
" print(i)"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -788,12 +819,27 @@ ...@@ -788,12 +819,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 5,
"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" "i=0\n",
"for i in A:\n",
" if i > 10:\n",
" print(i)"
] ]
}, },
{ {
...@@ -805,12 +851,21 @@ ...@@ -805,12 +851,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 14,
"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",
"print(set(a) & set(b))"
] ]
}, },
{ {
...@@ -839,11 +894,24 @@ ...@@ -839,11 +894,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 17,
"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",
"\n",
"def sumList(lista):\n",
" print(sum(lista))\n",
" \n",
"sumList(a)"
] ]
}, },
{ {
...@@ -855,11 +923,20 @@ ...@@ -855,11 +923,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [], "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",
"print(list(set(a)))"
] ]
}, },
{ {
...@@ -970,7 +1047,7 @@ ...@@ -970,7 +1047,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.3" "version": "3.5.2"
} }
}, },
"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