diff --git a/.iphyton/.ipynb_checkpoints/Ejercicio1-checkpoint.ipynb b/.iphyton/.ipynb_checkpoints/Ejercicio1-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..d3b054874c3d9030d20bc76ce1a64994f8085006 --- /dev/null +++ b/.iphyton/.ipynb_checkpoints/Ejercicio1-checkpoint.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## TAREA 2\n", + "# Asto Rojas, Omar" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Programa en Python que te permite ingresar una lista de palabras \n", + "\n", + "separadas por guión para despúes ordenarlas alfabéticamente, \n", + "\n", + "conservando el mismo formato de entrada." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "def Ordenar_lista(a):\n", + " \"\"\"\n", + " Función que te permite ordenar una lista que tiene palabras separadas por guiones.\n", + " Debes itroducir una lista de la siguiente forma: [\"word1-word2-word3\"]\n", + " \"\"\"\n", + " #Esta lÃnea crea una lista a partir de la introducida donde sus elementos\n", + " #son los que estaban seprados por guiones.\n", + " newlist1 = [word for line in a for word in line.split(\"-\")] \n", + " #En esta lÃnea primero se utiliza la función set para eliminar los elemntos iguales.\n", + " #Despúes con la función sorted se ordena la lista.\n", + " newlist2 = sorted(set(newlist1))\n", + " #En esta lÃnea se crea un conjunto de palabras donde cada una es separada por un guión\n", + " #como en el inicio\n", + " newlist3 = '-'.join(newlist2)\n", + " \n", + " print(a, newlist1, newlist2, newlist3)\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/.iphyton/.ipynb_checkpoints/Ejercicio2-checkpoint.ipynb b/.iphyton/.ipynb_checkpoints/Ejercicio2-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..d2525b2faa14d8329aaeaea92fdcc589182b3c68 --- /dev/null +++ b/.iphyton/.ipynb_checkpoints/Ejercicio2-checkpoint.ipynb @@ -0,0 +1,142 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Triángulo de Pascal\n", + "### Asto Rojas, Omar\n", + "\n", + "Programa que te permite obtener un elemento determinado\n", + "\n", + "del triángulo de Pascal." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def Pascal(n):\n", + " \"\"\"\n", + " El código solo corre si el número entregado es entero, \n", + " el comando if y la función isinstance(#, naturaleza de #)\n", + " permiten esto.\n", + " \"\"\"\n", + " if isinstance(n, int): \n", + " list=[1] ##una vez cumplida la condición, se crea una lista con el elemento 1\n", + " for i in range(n-1): ##recorre desde 0 al # que le entregemos\n", + " newlist=[] ## se crea otra lista\n", + " newlist.append(list[0]) ##en la nueva lista, se agrega el primer elemento de list\n", + " for i in range(len(list)-1): ## este for depende de la medida de list\n", + " newlist.append(list[i]+list[i+1]) ## hace que se agrege a la nueva lista la suma de un elemnto de list con el siguiente\n", + " newlist.append(list[-1]) ##agregas el último\n", + " list=newlist #aqué se reemplaza a la nueva lista por la nueva, para volver a la iteración\n", + " print(list)\n", + " if isinstance(n, float):\n", + " return \"introduzca_un_entero\"\n", + " else:\n", + " print(\"introduce un número\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Pascal(\"a\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Segunda parte del ejercicio:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def Pascal2(nums):\n", + " \"\"\"\n", + " Esta primera parte del ejercicio solo toma los enteros introducidos en la lista.\n", + " \"\"\"\n", + " new_list = []\n", + " for value in nums:\n", + " new_list.append(str(value)) \n", + " new = [x for x in new_list if x.isdigit()]\n", + " final = []\n", + " for value in new:\n", + " final.append(int(value))\n", + " \"\"\"\n", + " *******************************\n", + " Segunda parte, en donde se modifica el código del primer ejercicio.\n", + " \"\"\"\n", + " real_final = []\n", + " for value in final:\n", + " lists=[1] \n", + " for i in range(value): \n", + " newlist2=[] \n", + " newlist2.append(lists[0]) \n", + " for i in range(len(lists)-1): \n", + " newlist2.append(lists[i]+lists[i+1]) \n", + " newlist2.append(lists[-1]) \n", + " lists=newlist2\n", + " real_final.append(lists)\n", + " print(real_final)\n", + " result = []\n", + " for sublist in real_final:\n", + " for item in sublist:\n", + " result.append(item)\n", + " print(result)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 1], [1, 4, 6, 4, 1]]\n", + "[1, 2, 1, 1, 4, 6, 4, 1]\n" + ] + } + ], + "source": [ + "Pascal2([2,4])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/.iphyton/.ipynb_checkpoints/Ejercicio3-checkpoint.ipynb b/.iphyton/.ipynb_checkpoints/Ejercicio3-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..ad7c2372f5ab21894ffc3b04c692fef5e1f59dc3 --- /dev/null +++ b/.iphyton/.ipynb_checkpoints/Ejercicio3-checkpoint.ipynb @@ -0,0 +1,213 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Amigos congueros\n", + "### Asto Rojas, Omar\n" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "Amig_Cong = {\"andreatugores\" : {\"Nombre\" : \"Andrea Carolina\",\"Apellido\" : \"Tugores Hernádez\", \"Edad\" : 24, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Caracas\", \"Especialidad\" : \"FÃsica médica\", \"Institución\" : \"UCV\" , \"Hobbie\" : \"tennis\" },\n", + " \"arturos\" : {\"Nombre\" : \"Arturo\",\"Apellido\" : \"Sanchez\", \"Edad\" : 34, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Ginebra\", \"Especialidad\" : \"FÃsica\", \"Institución\" : \"LAPP\" , \"Hobbie\" : \"montar bicicleta\" },\n", + " \"grisalesj\" : {\"Nombre\" : \"Jennifer\",\"Apellido\" : \"Grisales\", \"Edad\" : 27, \"PaÃs\" : \"Colombia\", \"Residencia\" : \"Bucaramanga\", \"Especialidad\" : \"FÃsica\", \"Institución\" : \"UIS\" , \"Hobbie\" : \"rugby\" },\n", + " \"hernandezj\" : {\"Nombre\" : \"Juan David\",\"Apellido\" : \"Hernandez\", \"Edad\" : 24, \"PaÃs\" : \"Colombia\", \"Residencia\" : \"Bógota\", \"Especialidad\" : \"Electrodinámica Cuántica\", \"Institución\" : \"UNC\" , \"Hobbie\" : \"leer y jugar en el computador\" },\n", + " \"jal\" : {\"Nombre\" : \"José Antonio\", \"Apellido\" : \"López\", \"Edad\" : 50, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"\", \"Especialidad\" : \"FÃsica\", \"Institución\" : \"UCV\" , \"Hobbie\" : \"excursionismo, cocinar, leer.\" },\n", + " \"martinezj\" : {\"Nombre\" : \"Jocabed\",\"Apellido\" : \"Martinez\", \"Edad\" : 22, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Caracas\", \"Especialidad\" : \"\", \"Institución\" : \"UCV\" , \"Hobbie\" : \"música\" },\n", + " \"ramosm\" : {\"Nombre\" : \"MarÃa\",\"Apellido\" : \"Ramos\", \"Edad\" : 23, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Mérida\", \"Especialidad\" : \"\", \"Institución\" : \"UA\" , \"Hobbie\" : \"escribir\" },\n", + " \"vargass\" : {\"Nombre\" : \"Sasiri Juliana\", \"Apellido\" : \"Vargas Urbano\", \"Edad\" : 20, \"PaÃs\" : \"Colombia\", \"Especialidad\" : \"FÃsica estadÃstica\", \"Institución\" : \"Univalle\" , \"Hobbie\" : \"cantar, bailar y tacar instrumentos musicales: guitarra y flauta traversa.\" },\n", + " \"cristian.velandia\" : {\"Nombre\" : \"Cristian\",\"Apellido\" : \"Velandia\", \"Edad\" : 27, \"PaÃs\" : \"Colombia\", \"Residencia\": \"Colombia\", \"Especialidad\" : \"Óptica\", \"Institución\" : \"UNC\" , \"Hobbie\" : \"ánime y videojuegos\" },\n", + " \"ramosd\" : {\"Nombre\" : \"David\",\"Apellido\" : \"Ramos\", \"Edad\" : 24, \"PaÃs\" : \"Colombia\", \"Residencia\" : \"Bucaramanga\", \"Especialidad\" : \"AstrofÃsica relativista\", \"Institución\" : \"UIS\" , \"Hobbie\" : \"tocar guitarra\" }}" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Nombre': 'Andrea Carolina',\n", + " 'Apellido': 'Tugores Hernádez',\n", + " 'Edad': 24,\n", + " 'PaÃs': 'Venezuela',\n", + " 'Residencia': 'Caracas',\n", + " 'Especialidad': 'FÃsica médica',\n", + " 'Institución': 'UCV',\n", + " 'Hobbie': 'tennis'}" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Amig_Cong[\"andreatugores\"]\n", + "\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unexpected EOF while parsing (<ipython-input-41-914f065b3643>, line 12)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m\"<ipython-input-41-914f065b3643>\"\u001b[0;36m, line \u001b[0;32m12\u001b[0m\n\u001b[0;31m print(sum_math_v_vi_average(student_details)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unexpected EOF while parsing\n" + ] + } + ], + "source": [ + "def sum_math_v_vi_average(list_of_dicts, Nom_pais):\n", + " for d in list_of_dicts:\n", + " n1 = d.pop('V')\n", + " n2 = d.pop('VI')\n", + " d['V+VI'] = (n1 + n2)/2\n", + " return list_of_dicts \n", + "student_details= [\n", + " {'id' : 1, 'subject' : 'math', 'V' : 70, 'VI' : 82},\n", + " {'id' : 2, 'subject' : 'math', 'V' : 73, 'VI' : 74},\n", + " {'id' : 3, 'subject' : 'math', 'V' : 75, 'VI' : 86}\n", + "]\n", + "print(sum_math_v_vi_average(student_details, Nom_pais)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Dictionary length: 3\n", + "('pet', 'dog') removed\n", + "Dictionary length: 2\n", + "('fruit', 'apple') removed\n", + "Dictionary length: 1\n", + "('color', 'blue') removed\n", + "Dictionary length: 0\n", + "The dictionary has no item now...\n" + ] + } + ], + "source": [ + "a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}\n", + "\n", + "while True:\n", + " try:\n", + " print(f'Dictionary length: {len(a_dict)}')\n", + " item = a_dict.popitem()\n", + " # Do something with item here...\n", + " print(f'{item} removed')\n", + " except KeyError:\n", + " print('The dictionary has no item now...')\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "def test(dictt,keys):\n", + " return [list(d[k] for k in keys) for d in dictt] \n" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "string indices must be integers", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m<ipython-input-56-ef963dc32de9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mAmig_Cong\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"PaÃs\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<ipython-input-46-bddd753df120>\u001b[0m in \u001b[0;36mtest\u001b[0;34m(dictt, keys)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdictt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0md\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdictt\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<ipython-input-46-bddd753df120>\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdictt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0md\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdictt\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<ipython-input-46-bddd753df120>\u001b[0m in \u001b[0;36m<genexpr>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdictt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0md\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdictt\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: string indices must be integers" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'student_id': 1, 'name': 'Jean Castro', 'class': 'V'},\n", + " {'student_id': 2, 'name': 'Lula Powell', 'class': 'V'},\n", + " {'student_id': 3, 'name': 'Brian Howell', 'class': 'VI'},\n", + " {'student_id': 4, 'name': 'Lynne Foster', 'class': 'VI'},\n", + " {'student_id': 5, 'name': 'Zachary Simon', 'class': 'VII'}]" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "students = [\n", + " {'student_id': 1, 'name': 'Jean Castro', 'class': 'V'}, \n", + " {'student_id': 2, 'name': 'Lula Powell', 'class': 'V'},\n", + " {'student_id': 3, 'name': 'Brian Howell', 'class': 'VI'}, \n", + " {'student_id': 4, 'name': 'Lynne Foster', 'class': 'VI'}, \n", + " {'student_id': 5, 'name': 'Zachary Simon', 'class': 'VII'}\n", + " ]\n", + "list(students)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Ejercicio1.ipynb b/Ejercicio1.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..2ddceae19d4e7bb6eb28156550e8a43a15cc6657 --- /dev/null +++ b/Ejercicio1.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Lista de Palabras\n", + "# Asto Rojas, Omar" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Programa en Python que te permite ingresar una lista de palabras \n", + "\n", + "separadas por guión para despúes ordenarlas alfabéticamente, \n", + "\n", + "conservando el mismo formato de entrada." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "def Ordenar_lista(a):\n", + " \"\"\"\n", + " Función que te permite ordenar una lista que tiene palabras separadas por guiones.\n", + " Debes itroducir una lista de la siguiente forma: [\"word1-word2-word3\"]\n", + " \"\"\"\n", + " #Esta lÃnea crea una lista a partir de la introducida donde sus elementos\n", + " #son los que estaban seprados por guiones.\n", + " newlist1 = [word for line in a for word in line.split(\"-\")] \n", + " #En esta lÃnea primero se utiliza la función set para eliminar los elemntos iguales.\n", + " #Despúes con la función sorted se ordena la lista.\n", + " newlist2 = sorted(set(newlist1))\n", + " #En esta lÃnea se crea un conjunto de palabras donde cada una es separada por un guión\n", + " #como en el inicio\n", + " newlist3 = '-'.join(newlist2)\n", + " \n", + " print(a, newlist1, newlist2, newlist3)\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Ejercicio2.ipynb b/Ejercicio2.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..d2525b2faa14d8329aaeaea92fdcc589182b3c68 --- /dev/null +++ b/Ejercicio2.ipynb @@ -0,0 +1,142 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Triángulo de Pascal\n", + "### Asto Rojas, Omar\n", + "\n", + "Programa que te permite obtener un elemento determinado\n", + "\n", + "del triángulo de Pascal." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def Pascal(n):\n", + " \"\"\"\n", + " El código solo corre si el número entregado es entero, \n", + " el comando if y la función isinstance(#, naturaleza de #)\n", + " permiten esto.\n", + " \"\"\"\n", + " if isinstance(n, int): \n", + " list=[1] ##una vez cumplida la condición, se crea una lista con el elemento 1\n", + " for i in range(n-1): ##recorre desde 0 al # que le entregemos\n", + " newlist=[] ## se crea otra lista\n", + " newlist.append(list[0]) ##en la nueva lista, se agrega el primer elemento de list\n", + " for i in range(len(list)-1): ## este for depende de la medida de list\n", + " newlist.append(list[i]+list[i+1]) ## hace que se agrege a la nueva lista la suma de un elemnto de list con el siguiente\n", + " newlist.append(list[-1]) ##agregas el último\n", + " list=newlist #aqué se reemplaza a la nueva lista por la nueva, para volver a la iteración\n", + " print(list)\n", + " if isinstance(n, float):\n", + " return \"introduzca_un_entero\"\n", + " else:\n", + " print(\"introduce un número\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Pascal(\"a\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Segunda parte del ejercicio:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def Pascal2(nums):\n", + " \"\"\"\n", + " Esta primera parte del ejercicio solo toma los enteros introducidos en la lista.\n", + " \"\"\"\n", + " new_list = []\n", + " for value in nums:\n", + " new_list.append(str(value)) \n", + " new = [x for x in new_list if x.isdigit()]\n", + " final = []\n", + " for value in new:\n", + " final.append(int(value))\n", + " \"\"\"\n", + " *******************************\n", + " Segunda parte, en donde se modifica el código del primer ejercicio.\n", + " \"\"\"\n", + " real_final = []\n", + " for value in final:\n", + " lists=[1] \n", + " for i in range(value): \n", + " newlist2=[] \n", + " newlist2.append(lists[0]) \n", + " for i in range(len(lists)-1): \n", + " newlist2.append(lists[i]+lists[i+1]) \n", + " newlist2.append(lists[-1]) \n", + " lists=newlist2\n", + " real_final.append(lists)\n", + " print(real_final)\n", + " result = []\n", + " for sublist in real_final:\n", + " for item in sublist:\n", + " result.append(item)\n", + " print(result)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 1], [1, 4, 6, 4, 1]]\n", + "[1, 2, 1, 1, 4, 6, 4, 1]\n" + ] + } + ], + "source": [ + "Pascal2([2,4])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Ejercicio3.ipynb b/Ejercicio3.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..ad7c2372f5ab21894ffc3b04c692fef5e1f59dc3 --- /dev/null +++ b/Ejercicio3.ipynb @@ -0,0 +1,213 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Amigos congueros\n", + "### Asto Rojas, Omar\n" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "Amig_Cong = {\"andreatugores\" : {\"Nombre\" : \"Andrea Carolina\",\"Apellido\" : \"Tugores Hernádez\", \"Edad\" : 24, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Caracas\", \"Especialidad\" : \"FÃsica médica\", \"Institución\" : \"UCV\" , \"Hobbie\" : \"tennis\" },\n", + " \"arturos\" : {\"Nombre\" : \"Arturo\",\"Apellido\" : \"Sanchez\", \"Edad\" : 34, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Ginebra\", \"Especialidad\" : \"FÃsica\", \"Institución\" : \"LAPP\" , \"Hobbie\" : \"montar bicicleta\" },\n", + " \"grisalesj\" : {\"Nombre\" : \"Jennifer\",\"Apellido\" : \"Grisales\", \"Edad\" : 27, \"PaÃs\" : \"Colombia\", \"Residencia\" : \"Bucaramanga\", \"Especialidad\" : \"FÃsica\", \"Institución\" : \"UIS\" , \"Hobbie\" : \"rugby\" },\n", + " \"hernandezj\" : {\"Nombre\" : \"Juan David\",\"Apellido\" : \"Hernandez\", \"Edad\" : 24, \"PaÃs\" : \"Colombia\", \"Residencia\" : \"Bógota\", \"Especialidad\" : \"Electrodinámica Cuántica\", \"Institución\" : \"UNC\" , \"Hobbie\" : \"leer y jugar en el computador\" },\n", + " \"jal\" : {\"Nombre\" : \"José Antonio\", \"Apellido\" : \"López\", \"Edad\" : 50, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"\", \"Especialidad\" : \"FÃsica\", \"Institución\" : \"UCV\" , \"Hobbie\" : \"excursionismo, cocinar, leer.\" },\n", + " \"martinezj\" : {\"Nombre\" : \"Jocabed\",\"Apellido\" : \"Martinez\", \"Edad\" : 22, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Caracas\", \"Especialidad\" : \"\", \"Institución\" : \"UCV\" , \"Hobbie\" : \"música\" },\n", + " \"ramosm\" : {\"Nombre\" : \"MarÃa\",\"Apellido\" : \"Ramos\", \"Edad\" : 23, \"PaÃs\" : \"Venezuela\", \"Residencia\" : \"Mérida\", \"Especialidad\" : \"\", \"Institución\" : \"UA\" , \"Hobbie\" : \"escribir\" },\n", + " \"vargass\" : {\"Nombre\" : \"Sasiri Juliana\", \"Apellido\" : \"Vargas Urbano\", \"Edad\" : 20, \"PaÃs\" : \"Colombia\", \"Especialidad\" : \"FÃsica estadÃstica\", \"Institución\" : \"Univalle\" , \"Hobbie\" : \"cantar, bailar y tacar instrumentos musicales: guitarra y flauta traversa.\" },\n", + " \"cristian.velandia\" : {\"Nombre\" : \"Cristian\",\"Apellido\" : \"Velandia\", \"Edad\" : 27, \"PaÃs\" : \"Colombia\", \"Residencia\": \"Colombia\", \"Especialidad\" : \"Óptica\", \"Institución\" : \"UNC\" , \"Hobbie\" : \"ánime y videojuegos\" },\n", + " \"ramosd\" : {\"Nombre\" : \"David\",\"Apellido\" : \"Ramos\", \"Edad\" : 24, \"PaÃs\" : \"Colombia\", \"Residencia\" : \"Bucaramanga\", \"Especialidad\" : \"AstrofÃsica relativista\", \"Institución\" : \"UIS\" , \"Hobbie\" : \"tocar guitarra\" }}" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Nombre': 'Andrea Carolina',\n", + " 'Apellido': 'Tugores Hernádez',\n", + " 'Edad': 24,\n", + " 'PaÃs': 'Venezuela',\n", + " 'Residencia': 'Caracas',\n", + " 'Especialidad': 'FÃsica médica',\n", + " 'Institución': 'UCV',\n", + " 'Hobbie': 'tennis'}" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Amig_Cong[\"andreatugores\"]\n", + "\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unexpected EOF while parsing (<ipython-input-41-914f065b3643>, line 12)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m\"<ipython-input-41-914f065b3643>\"\u001b[0;36m, line \u001b[0;32m12\u001b[0m\n\u001b[0;31m print(sum_math_v_vi_average(student_details)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unexpected EOF while parsing\n" + ] + } + ], + "source": [ + "def sum_math_v_vi_average(list_of_dicts, Nom_pais):\n", + " for d in list_of_dicts:\n", + " n1 = d.pop('V')\n", + " n2 = d.pop('VI')\n", + " d['V+VI'] = (n1 + n2)/2\n", + " return list_of_dicts \n", + "student_details= [\n", + " {'id' : 1, 'subject' : 'math', 'V' : 70, 'VI' : 82},\n", + " {'id' : 2, 'subject' : 'math', 'V' : 73, 'VI' : 74},\n", + " {'id' : 3, 'subject' : 'math', 'V' : 75, 'VI' : 86}\n", + "]\n", + "print(sum_math_v_vi_average(student_details, Nom_pais)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Dictionary length: 3\n", + "('pet', 'dog') removed\n", + "Dictionary length: 2\n", + "('fruit', 'apple') removed\n", + "Dictionary length: 1\n", + "('color', 'blue') removed\n", + "Dictionary length: 0\n", + "The dictionary has no item now...\n" + ] + } + ], + "source": [ + "a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}\n", + "\n", + "while True:\n", + " try:\n", + " print(f'Dictionary length: {len(a_dict)}')\n", + " item = a_dict.popitem()\n", + " # Do something with item here...\n", + " print(f'{item} removed')\n", + " except KeyError:\n", + " print('The dictionary has no item now...')\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "def test(dictt,keys):\n", + " return [list(d[k] for k in keys) for d in dictt] \n" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "string indices must be integers", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m<ipython-input-56-ef963dc32de9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mAmig_Cong\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"PaÃs\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<ipython-input-46-bddd753df120>\u001b[0m in \u001b[0;36mtest\u001b[0;34m(dictt, keys)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdictt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0md\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdictt\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<ipython-input-46-bddd753df120>\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdictt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0md\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdictt\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<ipython-input-46-bddd753df120>\u001b[0m in \u001b[0;36m<genexpr>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdictt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0md\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdictt\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: string indices must be integers" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'student_id': 1, 'name': 'Jean Castro', 'class': 'V'},\n", + " {'student_id': 2, 'name': 'Lula Powell', 'class': 'V'},\n", + " {'student_id': 3, 'name': 'Brian Howell', 'class': 'VI'},\n", + " {'student_id': 4, 'name': 'Lynne Foster', 'class': 'VI'},\n", + " {'student_id': 5, 'name': 'Zachary Simon', 'class': 'VII'}]" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "students = [\n", + " {'student_id': 1, 'name': 'Jean Castro', 'class': 'V'}, \n", + " {'student_id': 2, 'name': 'Lula Powell', 'class': 'V'},\n", + " {'student_id': 3, 'name': 'Brian Howell', 'class': 'VI'}, \n", + " {'student_id': 4, 'name': 'Lynne Foster', 'class': 'VI'}, \n", + " {'student_id': 5, 'name': 'Zachary Simon', 'class': 'VII'}\n", + " ]\n", + "list(students)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}