{"id":1825,"date":"2016-02-04T14:10:17","date_gmt":"2016-02-04T19:10:17","guid":{"rendered":"http:\/\/blog.espol.edu.ec\/icm00794\/?p=1825"},"modified":"2026-04-05T18:08:08","modified_gmt":"2026-04-05T23:08:08","slug":"s2eva2015tii_t3-playaton-limpieza-de-playas","status":"publish","type":"post","link":"https:\/\/blog.espol.edu.ec\/algoritmos101\/fp-s2eva20\/s2eva2015tii_t3-playaton-limpieza-de-playas\/","title":{"rendered":"s2Eva2015TII_T3 Playaton limpieza de playas"},"content":{"rendered":"\n<p><strong><em>Ejercicio<\/em><\/strong>: <a href=\"https:\/\/blog.espol.edu.ec\/algoritmos101\/fp-2eva20\/2eva2015tii_t3-playaton-limpieza-de-playas\/\" data-type=\"post\" data-id=\"3044\">2Eva2015TII_T3 Playaton limpieza de playas<\/a><\/p>\n\n\n\n<p>Continuaci\u00f3n del tema 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Algoritmo en Python<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code alignwide\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# ICM00794-Fundamentos de Computaci\u00f3n - FCNM-ESPOL\n# 2Eva_IIT2015_T2 funcion totalportipo(tabla)\n# propuesta de repaso: edelros@espol.edu.ec\n\nimport numpy as np\n\ndef totalportipo(tabla):\n    # Tama\u00f1o de tabla con codigoplaya,recolectado\n    n,k = tabla.shape  \n    \n    # verifica banderas repetido cambiando a 1\n    repetidos = np.zeros(n,dtype=int)\n    i = 0\n    while not(i&gt;=(n-1)):\n        j = i + 1\n        while not(j&gt;=n):\n            if (tabla&#x5B;i,0]==tabla&#x5B;j,0]):\n                repetidos&#x5B;j] = 1\n            j = j+1\n        i = i + 1\n    \n    # cuenta los que se eliminan\n    # para ver los m que son \u00fanicos\n    eliminar = 0\n    fila = 0\n    while not(fila&gt;=n):\n        eliminar = eliminar + repetidos&#x5B;fila]\n        fila = fila + 1\n    m = n-eliminar\n\n    # copiar codigos unicos en tabulado columna 0\n    tabulado = np.zeros(shape=(m,3), dtype=float)\n    fila = 0\n    j = 0\n    while not(fila&gt;=n):\n        if (repetidos&#x5B;fila]==0):\n            tabulado&#x5B;j,0] = tabla&#x5B;fila,0]\n            j = j + 1\n        fila = fila + 1\n\n    # Cuenta voluntarios por playa en tabulado columna 1\n    # Acumula recolectado por playa en tabulado columna 2\n    fila = 0\n    while not(fila&gt;=n):\n        cual = tabla&#x5B;fila,0]\n        # encuentra el \u00edndice en donde\n        donde = np.where(tabulado&#x5B;:,0]==cual) \n        tabulado&#x5B;donde,1] = tabulado&#x5B;donde,1] + 1\n        tabulado&#x5B;donde,2] = tabulado&#x5B;donde,2] + tabla&#x5B;fila,1]\n        fila = fila + 1\n\n    # acumula lo recolectado por playa\n    return(tabulado)\n\n\n# 2Eva_IIT2015_T3 Playaton limpieza de playas\nvoluntarios = &#x5B;]\nopcion = 0\nwhile not(opcion==7):\n    print('1. registrar voluntario')\n    print('2. registrar Kg recolectada\/voluntario')\n    print('3. conteo de voluntarios')\n    print('4. tabular recolectado')\n    print('5. Guardar archivo')\n    print('6. Abrir archivo')\n    print('7. Salir')\n    \n    opcion = int(input(' opcion:'))\n    \n    if (opcion==1):\n        print('-- registrar voluntario --')\n        ced = int(input('c\u00e9dula: '))\n        nom = input('nombre: ')\n        pla = int(input('codigo playa: '))\n        rec = 0\n        registro = {'cedula':ced,\n                    'nombre': nom,\n                    'playa':pla,\n                    'recolectado':rec}\n        voluntarios.append(registro)\n        print('gracias por participar')\n\n    if (opcion==2):\n        print('-- registrar Kg recolectado\/voluntario --')\n        ced = int(input('c\u00e9dula: '))\n        rec = float(input('recolectado: '))\n        \n        # buscar voluntario,\n        # Podr\u00eda buscar con index en la lista\n        encontre = -1\n        n = len(voluntarios)\n        fila = 0\n        while not(encontre&gt;=0 or fila&gt;=n):\n            if (voluntarios&#x5B;fila]&#x5B;'cedula']==ced):\n                encontre = fila\n            fila = fila + 1\n        \n        if (encontre&gt;=0):\n            voluntarios&#x5B;encontre]&#x5B;'recolectado'] = rec\n            print('recolectado:',rec)\n        else:\n            print('no esta registrado este voluntario')\n\n    if (opcion==3):\n        print('--- cuenta voluntarios ---')\n        n = len(voluntarios)\n        # extraer columnas codigoplaya y recoletado\n        tabla = np.zeros(shape=(n,2),dtype=float)\n        fila = 0\n        while not(fila&gt;=n):\n          tabla&#x5B;fila]&#x5B;0] = voluntarios&#x5B;fila]&#x5B;'playa']\n          tabla&#x5B;fila]&#x5B;1] = voluntarios&#x5B;fila]&#x5B;'recolectado']\n          fila = fila + 1\n        resultado = totalportipo(tabla)\n\n        print('los voluntarios presentados son:',n)\n        print(resultado)\n\n    if (opcion==4):\n        print('-- tabular recolectado --')\n        n = len(voluntarios)\n        # extraer vector codigos playas\n        tabla = np.zeros(shape=(n,2),dtype=float)\n        fila = 0\n        while not(fila&gt;=n):\n          tabla&#x5B;fila]&#x5B;0] = voluntarios&#x5B;fila]&#x5B;'playa']\n          tabla&#x5B;fila]&#x5B;1] = voluntarios&#x5B;fila]&#x5B;'recolectado']\n          fila = fila + 1\n        resultado = totalportipo(tabla)\n\n        #total recolectado\n        m,k = resultado.shape\n        total = 0\n        i = 0\n        while not(i&gt;=m):\n            total = total + resultado&#x5B;i,2]\n            i = i + 1\n        print('El total recolectado es:',total)\n        print('El total por playa es: ')\n        print(resultado)\n\n    if (opcion==5):\n        print('---- guardar el archivo de voluntarios ---')\n        \n        # prepara el modo escritura 'w' de archivo\n        archivo = open('voluntarios.txt','w')\n        \n        n = len(voluntarios)\n        fila = 0\n        while not(fila&gt;=n):\n\n            # Crea la linea de texto de los datos\n            # para un registro, separada por comas\n            registro = str(voluntarios&#x5B;fila]&#x5B;'cedula'])\n            registro = registro + ',' + voluntarios&#x5B;fila]&#x5B;'nombre']\n            registro = registro + ',' +str(voluntarios&#x5B;fila]&#x5B;'playa'])\n            registro = registro + ',' +str(voluntarios&#x5B;fila]&#x5B;'recolectado']) +'\\n'\n\n            # Escribe en el archivo\n            archivo.write(registro)\n            fila = fila + 1\n\n        archivo.close()     # Cierra el archivo    \n        print('archivo guardado...')\n\n    if (opcion==6):\n        print(' --- Abrir archivo de voluntarios---')\n        voluntarios = &#x5B;]\n        \n        # prepara el modo lectura(read 'r') de archivo\n        archivo = open('voluntarios.txt','r')\n        linea = archivo.readline()\n\n        #Hasta encontrar el final del archivo\n        while (linea!=''):\n            # Divide los datos por comas\n            datos = linea.split(',')  \n            ced = int(datos&#x5B;0])\n            nom = datos&#x5B;1]\n            pla = int(datos&#x5B;2])\n            rec = float(datos&#x5B;3])\n            \n            # crea el registro diccionario para la lista\n            registro = {'cedula':ced,\n                        'nombre': nom,\n                        'playa':pla,\n                        'recolectado':rec}\n            \n            voluntarios.append(registro)\n            # Lee la siguiente linea\n            linea=archivo.readline()\n            \n        archivo.close()  # Cierra el archivo\n        \n        n = len(voluntarios)\n        print(' Se recuperaron '+ str(n) + ' registros de voluntarios')\n        \n    if (opcion==7):\n        print(' gracias por usar el software, @copyright')\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Ejercicio: 2Eva2015TII_T3 Playaton limpieza de playas Continuaci\u00f3n del tema 2. Algoritmo en Python<\/p>\n","protected":false},"author":8043,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"wp-custom-template-entrada-fp-ejemplos","format":"standard","meta":{"footnotes":""},"categories":[136],"tags":[58,157],"class_list":["post-1825","post","type-post","status-publish","format-standard","hentry","category-fp-s2eva20","tag-ejemplos-python","tag-fundamentos-programacion"],"_links":{"self":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/1825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/users\/8043"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/comments?post=1825"}],"version-history":[{"count":5,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/1825\/revisions"}],"predecessor-version":[{"id":23691,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/1825\/revisions\/23691"}],"wp:attachment":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/media?parent=1825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/categories?post=1825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/tags?post=1825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}