From 6316602ab15d169ba47e51053433ad949712efea Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 11:05:26 -0300 Subject: [PATCH 01/16] Criado usando o Colaboratory --- Desafio_01.ipynb | 201 ++++++++++++++++++++++++++++------------------- 1 file changed, 118 insertions(+), 83 deletions(-) diff --git a/Desafio_01.ipynb b/Desafio_01.ipynb index db922b9..f529c11 100644 --- a/Desafio_01.ipynb +++ b/Desafio_01.ipynb @@ -1,85 +1,120 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_01.ipynb", + "provenance": [], + "authorship_tag": "ABX9TyNmwryVGQoS6/AS74yzoTFf", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "SbLLE9q1eldC" - }, - "source": [ - "### Desafio 1\n", - "\n", - "Escreva um programa em Python para contabilizar a quantidade de ocorrências de cada palavra." - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "WhtbdwFseldD" - }, - "outputs": [], - "source": [ - "palavras = [\n", - " 'red', 'green', 'black', 'pink', 'black', 'white', 'black', 'eyes',\n", - " 'white', 'black', 'orange', 'pink', 'pink', 'red', 'red', 'white', 'orange',\n", - " 'white', \"black\", 'pink', 'green', 'green', 'pink', 'green', 'pink',\n", - " 'white', 'orange', \"orange\", 'red'\n", - "]\n", - "\n", - "\n", - "# Seu código" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "M58o1U9KfAxa" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 1.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-sFLbI5BS3hn" + }, + "source": [ + "Escreva um programa em Python para contabilizar a quantidade de ocorrências de cada palavra.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "mAteVeM2SISr" + }, + "source": [ + "#lista de palavras\n", + "palavras = [\n", + " 'red', 'green', 'black', 'pink', 'black', 'white', 'black', 'eyes',\n", + " 'white', 'black', 'orange', 'pink', 'pink', 'red', 'red', 'white', 'orange',\n", + " 'white', \"black\", 'pink', 'green', 'green', 'pink', 'green', 'pink',\n", + " 'white', 'orange', \"orange\", 'red'\n", + "]" + ], + "execution_count": 2, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "xonP_yDRSlTv", + "outputId": "b0e34832-f6c4-463a-d02b-84b7e4799290" + }, + "source": [ + "#Quantidade de elementos total na minha lista\n", + "len(palavras)" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "29" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 4 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "C7v7szsESwaP", + "outputId": "5900b556-4fc9-4548-f3f4-4127f12d61e5" + }, + "source": [ + "#ordenando e selecionando apenas os elementos únicos da minha lista\n", + "distinto = sorted(set(palavras))\n", + "\n", + "#Exibindo a quantidade de elementos na minha lista\n", + "for i in distinto:\n", + " print(f\"{i}, aparece na lista {palavras.count(i)} vezes\")" + ], + "execution_count": 24, + "outputs": [ + { + "output_type": "stream", + "text": [ + "black, aparece na lista 5 vezes\n", + "eyes, aparece na lista 1 vezes\n", + "green, aparece na lista 4 vezes\n", + "orange, aparece na lista 4 vezes\n", + "pink, aparece na lista 6 vezes\n", + "red, aparece na lista 4 vezes\n", + "white, aparece na lista 5 vezes\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 73f65bdfda51e3ff701226f037d4da9ca9ff6294 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 11:10:11 -0300 Subject: [PATCH 02/16] Criado usando o Colaboratory --- Desafio_02.ipynb | 152 +++++++++++++++++++++++++---------------------- 1 file changed, 82 insertions(+), 70 deletions(-) diff --git a/Desafio_02.ipynb b/Desafio_02.ipynb index 8aa2264..91ba239 100644 --- a/Desafio_02.ipynb +++ b/Desafio_02.ipynb @@ -1,72 +1,84 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_02.ipynb", + "provenance": [], + "authorship_tag": "ABX9TyM7EhF1QGzFH1jlpo6wm60e", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "q1NCks7Af6JN" - }, - "source": [ - "### Desafio 2\n", - "\n", - "Escreva uma função que receba um número inteiro de horas e converta esse número para segundos.\n", - "\n", - "Exemplo:\n", - "\n", - "convert(5) ➞ 18000\n", - "\n", - "convert(3) ➞ 10800\n", - "\n", - "convert(2) ➞ 7200" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "sSm6F7sff6JO" - }, - "outputs": [], - "source": [ - "def convert_to_sec(number):\n", - " pass # Seu código" - ] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 2.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XNt8sYYcZfCH" + }, + "source": [ + "Escreva uma função que receba um número inteiro de horas e converta esse número para segundos.\n", + "\n", + "Exemplo:\n", + "\n", + "convert(5) ➞ 18000\n", + "\n", + "convert(3) ➞ 10800\n", + "\n", + "convert(2) ➞ 7200\n", + "\n", + "def convert_to_sec(number):\n", + " pass # Seu código" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "b3Ko080eZasf", + "outputId": "4b3d0e76-8bd6-4f81-a50c-5d5db8e941f6" + }, + "source": [ + "#Convertendo horas em segundos\n", + "def convert_to_sec(number):\n", + " return number*3600\n", + "\n", + "#Validação\n", + "convert_to_sec(5)" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "18000" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 4 + } + ] + } + ] +} \ No newline at end of file From 099f0ea164d212012e034239ae52130b0c632596 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 11:13:55 -0300 Subject: [PATCH 03/16] Criado usando o Colaboratory --- Desafio_03.ipynb | 152 +++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 77 deletions(-) diff --git a/Desafio_03.ipynb b/Desafio_03.ipynb index 75be003..215ee23 100644 --- a/Desafio_03.ipynb +++ b/Desafio_03.ipynb @@ -1,79 +1,77 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_03.ipynb", + "provenance": [], + "authorship_tag": "ABX9TyPOg1AALwmQJ/qUARKwMvue", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "9apVxxygf6JR" - }, - "source": [ - "### Desafio 3\n", - "\n", - "Escreva uma função que receba uma lista como entrada e retorne uma nova lista ordenada e sem valores duplicados.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "ndTkQEUBf6JS" - }, - "outputs": [], - "source": [ - "lista = [1,2,3,4,3,30,3,4,5,6,9,3,2,1,2,4,5,15,6,6,3,13,4,45,5]\n", - "\n", - "# Seu código" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "wo2rA-NriFtO" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 3.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "egqeGF0aako6" + }, + "source": [ + "Escreva uma função que receba uma lista como entrada e retorne uma nova lista ordenada e sem valores duplicados." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gj9kO44FaffV" + }, + "source": [ + "#Lista de valores\n", + "lista = [1,2,3,4,3,30,3,4,5,6,9,3,2,1,2,4,5,15,6,6,3,13,4,45,5]" + ], + "execution_count": 1, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "S__igKuDaton", + "outputId": "72f99c50-fdde-48ea-ef62-c0481d67fdf9" + }, + "source": [ + "#Lista com valores únicos e ordenados\n", + "lista_unica = sorted(set(lista))\n", + "print(lista_unica)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 9, 13, 15, 30, 45]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From fb6c2a1616666cb51e5129a4711d65125c8f0c1c Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 18:17:06 -0300 Subject: [PATCH 04/16] Criado usando o Colaboratory --- Desafio_04.ipynb | 144 +++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 68 deletions(-) diff --git a/Desafio_04.ipynb b/Desafio_04.ipynb index bdab516..8ea80c1 100644 --- a/Desafio_04.ipynb +++ b/Desafio_04.ipynb @@ -1,70 +1,78 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_04.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyNc3AwhFrtYRGxDR1l+Fg82", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "dOqcKUYZf6JW" - }, - "source": [ - "### Desafio 4\n", - "\n", - "Escreva uma função cuja entrada é uma string e a saída é outra string com as palavras em ordem inversa.\n", - "\n", - "Exemplo:\n", - "\n", - "inverte_texto(\"Python é legal\") ➞ \"legal é Python\"" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "I5TInJDaf6JW" - }, - "outputs": [], - "source": [ - "# Seu código" - ] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 4.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "c2Ivg-LabcJY" + }, + "source": [ + "Escreva uma função cuja entrada é uma string e a saída é outra string com as palavras em ordem inversa.\n", + "\n", + "Exemplo:\n", + "\n", + "inverte_texto(\"Python é legal\") ➞ \"legal é Python\"" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "KwE6XAeObWMy", + "outputId": "ed5a6b7f-e234-4b08-8ec6-1dce8ce87bf2" + }, + "source": [ + "#Escrevendo as palavras em ordem inversa\n", + "texto = \"python é legal\"\n", + "\n", + "def inverter_texto(texto):\n", + " #Dividindo o texto em partes\n", + " inverso = texto.split()\n", + " #Invertendo o texto e juntando\n", + " print(\" \".join(inverso[::-1]))\n", + "\n", + "#chamada da função inverter\n", + "inverter_texto(texto)\n" + ], + "execution_count": 20, + "outputs": [ + { + "output_type": "stream", + "text": [ + "legal é python\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 73b80f1daef997b6c8884a9741f56959e53c3479 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 18:41:26 -0300 Subject: [PATCH 05/16] Criado usando o Colaboratory --- Desafio_05.ipynb | 214 +++++++++++++++++++++++++---------------------- 1 file changed, 115 insertions(+), 99 deletions(-) diff --git a/Desafio_05.ipynb b/Desafio_05.ipynb index 0794a31..6b4238e 100644 --- a/Desafio_05.ipynb +++ b/Desafio_05.ipynb @@ -1,101 +1,117 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_05.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyMaVMKvFWWkJfqI8lZDVnMi", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "gQbaWOWcW1g_" - }, - "source": [ - "# Desafio 5\n", - "Você trabalha em uma loja de sapatos e deve contatar uma série de clientes. Seus números de telefone estão na lista abaixo. No entanto, é possível notar números duplicados na lista dada. Você seria capaz de remover estes duplicados para evitar que clientes sejam contatados mais de uma vez?" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "T68FjcUmWear" - }, - "outputs": [], - "source": [ - "numeros_telefone = [\n", - "'(765) 368-1506',\n", - "'(285) 608-2448',\n", - "'(255) 826-9050',\n", - "'(554) 994-1517',\n", - "'(285) 608-2448',\n", - "'(596) 336-5508',\n", - "'(511) 821-7870',\n", - "'(410) 665-4447',\n", - "'(821) 642-8987',\n", - "'(285) 608-2448',\n", - "'(311) 799-3883',\n", - "'(935) 875-2054',\n", - "'(464) 788-2397',\n", - "'(765) 368-1506',\n", - "'(650) 684-1437',\n", - "'(812) 816-0881',\n", - "'(285) 608-2448',\n", - "'(885) 407-1719',\n", - "'(943) 769-1061',\n", - "'(596) 336-5508',\n", - "'(765) 368-1506',\n", - "'(255) 826-9050',\n", - "]" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "F8n1sN-4XrW3" - }, - "outputs": [], - "source": [ - "#Seu código" - ] - } - ], - "metadata": { - "colab": { - "authorship_tag": "ABX9TyO0u4amKtoFgAgnb/IGUddy", - "include_colab_link": true, - "name": "Desafio 5.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P6rCoteG8QhF" + }, + "source": [ + "Você trabalha em uma loja de sapatos e deve contatar uma série de clientes. Seus números de telefone estão na lista abaixo. No entanto, é possível notar números duplicados na lista dada. Você seria capaz de remover estes duplicados para evitar que clientes sejam contatados mais de uma vez?" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "bFRYC_0O8L1y" + }, + "source": [ + "numeros_telefone = [\n", + "'(765) 368-1506',\n", + "'(285) 608-2448',\n", + "'(255) 826-9050',\n", + "'(554) 994-1517',\n", + "'(285) 608-2448',\n", + "'(596) 336-5508',\n", + "'(511) 821-7870',\n", + "'(410) 665-4447',\n", + "'(821) 642-8987',\n", + "'(285) 608-2448',\n", + "'(311) 799-3883',\n", + "'(935) 875-2054',\n", + "'(464) 788-2397',\n", + "'(765) 368-1506',\n", + "'(650) 684-1437',\n", + "'(812) 816-0881',\n", + "'(285) 608-2448',\n", + "'(885) 407-1719',\n", + "'(943) 769-1061',\n", + "'(596) 336-5508',\n", + "'(765) 368-1506',\n", + "'(255) 826-9050',\n", + "]" + ], + "execution_count": 1, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "A22QuqHZ8at9", + "outputId": "aecc5a94-2795-4610-d1ee-519c78b97e9d" + }, + "source": [ + "#Exibindo uma lista única sem caracteres\n", + "for i in set(numeros_telefone):\n", + " print(i)\n", + "\n", + "#Poderia ser dessa forma, mas acho esteticamente feia\n", + "#print(set(numeros_telefone))" + ], + "execution_count": 34, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(943) 769-1061\n", + "(821) 642-8987\n", + "(464) 788-2397\n", + "(311) 799-3883\n", + "(650) 684-1437\n", + "(554) 994-1517\n", + "(596) 336-5508\n", + "(511) 821-7870\n", + "(935) 875-2054\n", + "(885) 407-1719\n", + "(255) 826-9050\n", + "(410) 665-4447\n", + "(765) 368-1506\n", + "(812) 816-0881\n", + "(285) 608-2448\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From a4f31dcbc7e0afd13525167965cf1a8bb3dabc65 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 19:01:40 -0300 Subject: [PATCH 06/16] Criado usando o Colaboratory --- Desafio_09.ipynb | 154 ++++++++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/Desafio_09.ipynb b/Desafio_09.ipynb index 6fb29e1..e23ffa4 100644 --- a/Desafio_09.ipynb +++ b/Desafio_09.ipynb @@ -1,78 +1,80 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_09.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyPgldT5E4dubCk+9FAWcnsD", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "HpvTpUBGf6Jr" - }, - "source": [ - "### Desafio 9\n", - "\n", - "Escreva uma função que retorne a soma dos múltiplos de 3 e 5 entre 0 e um número limite, que vai ser utilizado como parâmetro. \\\n", - "Por exemplo, se o limite for 20, ele retornará a soma de 3, 5, 6, 9, 10, 12, 15, 18, 20." - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "195C6bw-f6Js" - }, - "outputs": [], - "source": [ - "# Seu código" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "a_6aqcKp6wrN" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 9.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "S-Z7j_caCQvb" + }, + "source": [ + "Escreva uma função que retorne a soma dos múltiplos de 3 e 5 entre 0 e um número limite, que vai ser utilizado como parâmetro. \\ Por exemplo, se o limite for 20, ele retornará a soma de 3, 5, 6, 9, 10, 12, 15, 18, 20." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hEgUMunLCQCB", + "outputId": "8f47f10f-9d30-4ff9-f79b-bcd665bbbe59" + }, + "source": [ + "#Função para retornar os multiplos de 3 e 5\n", + "def multiplo_3_5(limite):\n", + " for i in range(1, limite+1):\n", + " #Para saber se é um multiplo eu verifico se o resto da divisão por 3 e 5 é zero\n", + " if i%3 == 0 or i%5 == 0:\n", + " print(i)\n", + " \n", + "#Printando o resultado\n", + "multiplo_3_5(20)" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + "3\n", + "5\n", + "6\n", + "9\n", + "10\n", + "12\n", + "15\n", + "18\n", + "20\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 7d082f6e7718184c6d606f82d6baa9aadeeddb59 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sat, 22 May 2021 19:13:25 -0300 Subject: [PATCH 07/16] Criado usando o Colaboratory --- Desafio_09.ipynb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Desafio_09.ipynb b/Desafio_09.ipynb index e23ffa4..20a4ea0 100644 --- a/Desafio_09.ipynb +++ b/Desafio_09.ipynb @@ -6,7 +6,7 @@ "name": "Desafio_09.ipynb", "provenance": [], "collapsed_sections": [], - "authorship_tag": "ABX9TyPgldT5E4dubCk+9FAWcnsD", + "authorship_tag": "ABX9TyMFrI549S0eDgToEuCH7Qh5", "include_colab_link": true }, "kernelspec": { @@ -44,33 +44,27 @@ "base_uri": "https://localhost:8080/" }, "id": "hEgUMunLCQCB", - "outputId": "8f47f10f-9d30-4ff9-f79b-bcd665bbbe59" + "outputId": "5a99b27d-fa20-49ae-ba02-5e8437ea2eee" }, "source": [ "#Função para retornar os multiplos de 3 e 5\n", + "valores = []\n", "def multiplo_3_5(limite):\n", " for i in range(1, limite+1):\n", " #Para saber se é um multiplo eu verifico se o resto da divisão por 3 e 5 é zero\n", " if i%3 == 0 or i%5 == 0:\n", - " print(i)\n", - " \n", + " valores.append(i)\n", + " print(sum(valores))\n", + " \n", "#Printando o resultado\n", "multiplo_3_5(20)" ], - "execution_count": 7, + "execution_count": 30, "outputs": [ { "output_type": "stream", "text": [ - "3\n", - "5\n", - "6\n", - "9\n", - "10\n", - "12\n", - "15\n", - "18\n", - "20\n" + "98\n" ], "name": "stdout" } From 7ec11370d88cde1f02723ad410c1ab9595a5d308 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sun, 23 May 2021 15:09:27 -0300 Subject: [PATCH 08/16] Criado usando o Colaboratory --- Desafio_06.ipynb | 249 ++++++++++++++++++++++++++++++----------------- 1 file changed, 157 insertions(+), 92 deletions(-) diff --git a/Desafio_06.ipynb b/Desafio_06.ipynb index 1381088..37c8e8f 100644 --- a/Desafio_06.ipynb +++ b/Desafio_06.ipynb @@ -1,94 +1,159 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_06.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyPrEpup1RZFJzW5wL62cTLn", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "AiI1_KNTf6Jh" - }, - "source": [ - "### Desafio 6\n", - "\n", - "Crie uma função que receba duas listas e retorne uma lista que contenha apenas os elementos comuns entre as listas (sem repetição). A função deve suportar lista de tamanhos diferentes.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Listas**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "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]" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "mvxpy_vCf6Jh" - }, - "outputs": [], - "source": [ - "# Seu código" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "ly-N_Aq624RQ" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 6.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "VY0vIdMoBwL9" + }, + "source": [ + "Crie uma função que receba duas listas e retorne uma lista que contenha apenas os elementos comuns entre as listas (sem repetição). A função deve suportar lista de tamanhos diferentes." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PRmjtrdEBthN" + }, + "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]" + ], + "execution_count": 28, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "yXpMJtD0ZpXj", + "outputId": "255ebac5-51e6-4805-df77-2cc412fa36dd" + }, + "source": [ + "#Forma mais simples\n", + "def listaUnica(a,b):\n", + " resultado = set(a + b)\n", + " return resultado\n", + "\n", + "listaUnica(a,b)\n" + ], + "execution_count": 54, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 21, 34, 55, 89}" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 54 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "uQX9mFXORGnh", + "outputId": "223b1b68-0394-4d54-caa9-127b00a01959" + }, + "source": [ + "#Utilizando for mais função itertools\n", + "\n", + "def juncaoListas(a,b):\n", + " #importando a Biblioteca itertools\n", + " import itertools\n", + " #Criando as listas auxiliares\n", + " novaLista = []\n", + " listaUnica = []\n", + " #Chamando a função zip_longest da biblioteca itertools\n", + " for i,j in itertools.zip_longest(a,b, fillvalue=a[0]):\n", + " #Adicionando os elementos à lista\n", + " novaLista.append(i)\n", + " novaLista.append(j)\n", + " #Criando a lista única\n", + " listaUnica = set(novaLista)\n", + " print(listaUnica)\n", + "\n", + "juncaoListas(a,b)\n" + ], + "execution_count": 43, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{1, 2, 3, 4, 5, 6, 7, 8, 34, 9, 10, 11, 13, 12, 21, 55, 89}\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "zLo6r4jtYt6y", + "outputId": "a1681fb1-19f6-4f5f-d1d3-6ee5ce8ce289" + }, + "source": [ + "#Segunda Forma com muitas iterações\n", + "\n", + "def niteracoes(a,b):\n", + " lista3 = []\n", + " for i in a:\n", + " for j in b:\n", + " lista3.append(j)\n", + " lista3.append(i)\n", + " print(set(lista3))\n", + "\n", + "niteracoes(a,b)\n" + ], + "execution_count": 53, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 21, 55, 89}\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 6a638fdaebb2a38d910323f7a9e9778fb8e91404 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sun, 23 May 2021 15:34:50 -0300 Subject: [PATCH 09/16] Criado usando o Colaboratory --- Desafio_07.ipynb | 261 ++++++++++++++++++++++++----------------------- 1 file changed, 131 insertions(+), 130 deletions(-) diff --git a/Desafio_07.ipynb b/Desafio_07.ipynb index 55c90e7..307d50c 100644 --- a/Desafio_07.ipynb +++ b/Desafio_07.ipynb @@ -1,132 +1,133 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_07.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyOXJjqtDteC5XmeSjVPfiB3", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "gQbaWOWcW1g_" - }, - "source": [ - "# Desafio 7\n", - "Um professor de universidade tem uma turma com os seguintes números de telefones:" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "T68FjcUmWear" - }, - "outputs": [], - "source": [ - "telefones_alunos = ['(873) 810-8267', '(633) 244-7325', '(300) 303-5462', \n", - " '(938) 300-8890', '(429) 264-7427', '(737) 805-2326', \n", - " '(768) 956-8497', '(941) 225-3869', '(203) 606-9463', \n", - " '(294) 430-7720', '(896) 781-5087', '(397) 845-8267', \n", - " '(788) 717-6858', '(419) 734-4188', '(682) 595-3278', \n", - " '(835) 955-1498', '(296) 415-9944', '(897) 932-2512', \n", - " '(263) 415-3893', '(822) 640-8496', '(640) 427-2597', \n", - " '(856) 338-7094', '(807) 554-4076', '(641) 367-5279', \n", - " '(828) 866-0696', '(727) 376-5749', '(921) 948-2244', \n", - " '(964) 710-9625', '(596) 685-1242', '(403) 343-7705', \n", - " '(227) 389-3685', '(264) 372-7298', '(797) 649-3653', \n", - " '(374) 361-3844', '(618) 490-4228', '(987) 803-5550', \n", - " '(228) 976-9699', '(757) 450-9985', '(491) 666-5367',\n", - " ]" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "ryYrStScXgZ3" - }, - "source": [ - "Ele criou um grupo do WhatsApp. No entanto, somente os seguintes números entraram no grupo." - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "0Hxk13ciXZ3h" - }, - "outputs": [], - "source": [ - "entraram_no_grupo = ['(596) 685-1242', '(727) 376-5749', '(987) 803-5550', \n", - " '(633) 244-7325', '(828) 866-0696', '(263) 415-3893', \n", - " '(203) 606-9463', '(296) 415-9944', '(419) 734-4188', \n", - " '(618) 490-4228', '(682) 595-3278', '(938) 300-8890', \n", - " '(264) 372-7298', '(768) 956-8497', '(737) 805-2326', \n", - " '(788) 717-6858', '(228) 976-9699', '(896) 781-5087',\n", - " '(374) 361-3844', '(921) 948-2244', '(807) 554-4076', \n", - " '(822) 640-8496', '(227) 389-3685', '(429) 264-7427', \n", - " '(397) 845-8267']" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "-inLXlaxoWnC" - }, - "source": [ - "Você seria capaz de criar uma lista dos alunos que ainda não entraram no grupo para que sejam contatados individualmente?" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "_OSrDQ1noh62" - }, - "outputs": [], - "source": [ - "#Seu código." - ] - } - ], - "metadata": { - "colab": { - "authorship_tag": "ABX9TyPinyzdF60Dyi+YfEQiCPfO", - "include_colab_link": true, - "name": "Desafio 7.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XLMx8s7WbN42" + }, + "source": [ + "Um professor de universidade tem uma turma com os seguintes números de telefones:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "U2vd60qcbEbP" + }, + "source": [ + "telefones_alunos = ['(873) 810-8267', '(633) 244-7325', '(300) 303-5462', \n", + " '(938) 300-8890', '(429) 264-7427', '(737) 805-2326', \n", + " '(768) 956-8497', '(941) 225-3869', '(203) 606-9463', \n", + " '(294) 430-7720', '(896) 781-5087', '(397) 845-8267', \n", + " '(788) 717-6858', '(419) 734-4188', '(682) 595-3278', \n", + " '(835) 955-1498', '(296) 415-9944', '(897) 932-2512', \n", + " '(263) 415-3893', '(822) 640-8496', '(640) 427-2597', \n", + " '(856) 338-7094', '(807) 554-4076', '(641) 367-5279', \n", + " '(828) 866-0696', '(727) 376-5749', '(921) 948-2244', \n", + " '(964) 710-9625', '(596) 685-1242', '(403) 343-7705', \n", + " '(227) 389-3685', '(264) 372-7298', '(797) 649-3653', \n", + " '(374) 361-3844', '(618) 490-4228', '(987) 803-5550', \n", + " '(228) 976-9699', '(757) 450-9985', '(491) 666-5367',\n", + " ]" + ], + "execution_count": 2, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XE2B8IAzbR4r" + }, + "source": [ + "Ele criou um grupo do WhatsApp. No entanto, somente os seguintes números entraram no grupo." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Wq7LBgXjbQGs" + }, + "source": [ + "entraram_no_grupo = ['(596) 685-1242', '(727) 376-5749', '(987) 803-5550', \n", + " '(633) 244-7325', '(828) 866-0696', '(263) 415-3893', \n", + " '(203) 606-9463', '(296) 415-9944', '(419) 734-4188', \n", + " '(618) 490-4228', '(682) 595-3278', '(938) 300-8890', \n", + " '(264) 372-7298', '(768) 956-8497', '(737) 805-2326', \n", + " '(788) 717-6858', '(228) 976-9699', '(896) 781-5087',\n", + " '(374) 361-3844', '(921) 948-2244', '(807) 554-4076', \n", + " '(822) 640-8496', '(227) 389-3685', '(429) 264-7427', \n", + " '(397) 845-8267'\n", + " ]" + ], + "execution_count": 1, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qpu9OakjbXIL" + }, + "source": [ + "Você seria capaz de criar uma lista dos alunos que ainda não entraram no grupo para que sejam contatados individualmente?" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "bFB_I7Pbbcv7", + "outputId": "00805143-c3ab-4b48-8f8b-675678ac3a6b" + }, + "source": [ + "#Transformando listas em conjuntos (sets)\n", + "setTelefone_alunos = set(telefones_alunos)\n", + "#Transformando listas em conjuntos (sets)\n", + "setEntraram_no_grupo = set(entraram_no_grupo)\n", + "#Realizando a subtração dos telefones dos alunos menos os que entraram no whatsapp\n", + "resultado = setTelefone_alunos - setEntraram_no_grupo\n", + "#Imprimindo o resultado\n", + "print(resultado)" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + "{'(835) 955-1498', '(856) 338-7094', '(300) 303-5462', '(641) 367-5279', '(797) 649-3653', '(757) 450-9985', '(491) 666-5367', '(964) 710-9625', '(873) 810-8267', '(403) 343-7705', '(294) 430-7720', '(640) 427-2597', '(941) 225-3869', '(897) 932-2512'}\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From a606fbf0d9e2285d1e6614b8615398b663e56519 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sun, 23 May 2021 17:02:07 -0300 Subject: [PATCH 10/16] Criado usando o Colaboratory --- Desafio_08.ipynb | 231 +++++++++++++++++++++++++++++++---------------- 1 file changed, 155 insertions(+), 76 deletions(-) diff --git a/Desafio_08.ipynb b/Desafio_08.ipynb index de5d802..7189eeb 100644 --- a/Desafio_08.ipynb +++ b/Desafio_08.ipynb @@ -1,78 +1,157 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_08.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyNJJlGn9JKc3W1ThaTq9GQ/", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "o3tkeMDNf6Jo" - }, - "source": [ - "### Desafio 8\n", - "\n", - "Escreva um script Python para encontrar as 10 palavras mais longas em um arquivo de texto.\n", - "O arquivo .txt está localizado na mesma pasta do projeto (**texto.txt**)." - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "EknxjSG0f6Jo" - }, - "outputs": [], - "source": [ - "# Seu código" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "ZYbqEWBG5nKx" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 8.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "b3jQucMDgu50" + }, + "source": [ + "Escreva um script Python para encontrar as 10 palavras mais longas em um arquivo de texto. O arquivo .txt está localizado na mesma pasta do projeto (texto.txt)." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "MnZCeH-lgqmg", + "outputId": "2334d451-8013-4b3c-ed55-9d8bab23fe45" + }, + "source": [ + "#Importando o arquivo texto.txt do github\n", + "!wget https://raw.githubusercontent.com/matcarvalho/br-python-challenges/master/texto.txt" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "--2021-05-23 18:36:13-- https://raw.githubusercontent.com/matcarvalho/br-python-challenges/master/texto.txt\n", + "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...\n", + "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 766 [text/plain]\n", + "Saving to: ‘texto.txt’\n", + "\n", + "texto.txt 100%[===================>] 766 --.-KB/s in 0s \n", + "\n", + "2021-05-23 18:36:14 (34.9 MB/s) - ‘texto.txt’ saved [766/766]\n", + "\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hMrSUZX9kJMq", + "outputId": "95fdc2b4-4db8-4357-9a34-554f17d4fcbd" + }, + "source": [ + "# https://algoritmosempython.com.br/cursos/programacao-python/conjuntos/\n", + "\n", + "arq = open(\"texto.txt\") #carregando o arquivo\n", + "text = arq.readlines() #Lendo o conteúdo do arquivo\n", + "text #Exibindo o conteúdo do arquivo" + ], + "execution_count": 31, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['What is Python language? \\n',\n", + " 'Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in \\n',\n", + " 'languages such as C++ or Java. \\n',\n", + " 'Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles.It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.The best way we learn anything is by practice and exercise questions. We have started this section for those (beginner to intermediate) who are familiar with Python.']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 31 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "mieeF14EmKbq", + "outputId": "f269db48-7abe-4989-da41-a5f1dc3a0e84" + }, + "source": [ + "import string #Importando a biblioteca string\n", + "\n", + "# Chamando a função que carrega caracteres não alfanumérico string.punctuation\n", + "# O list comprehension verifica letra por letra para separar na nova lista somente palavras.\n", + "new_text = \"\".join([w for w in str(text) if w not in string.punctuation])\n", + "\n", + "# Sorted -> Ordena a lista | Atributo key -> como será classificado | reverse é o tipo de ordenação - > true é decrescente\n", + "# set -> Transforma a lista em valores únicos\n", + "# split -> Separa as palavras pelos espaços\n", + "# [0:10] -> somente os 10 primeiros\n", + "sorted(set(new_text.split(\" \")), key=len, reverse=True)[0:10]" + ], + "execution_count": 60, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['objectoriented',\n", + " 'generalpurpose',\n", + " 'comprehensive',\n", + " 'intermediate',\n", + " 'programming',\n", + " 'readability',\n", + " 'languageIts',\n", + " 'interpreted',\n", + " 'programmers',\n", + " 'imperative']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 60 + } + ] + } + ] +} \ No newline at end of file From 4a4af69086fe6306c80da057018df1d467e8f050 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sun, 23 May 2021 23:06:45 -0300 Subject: [PATCH 11/16] Criado usando o Colaboratory --- Desafio_10.ipynb | 179 +++++++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 85 deletions(-) diff --git a/Desafio_10.ipynb b/Desafio_10.ipynb index 4f831f3..4b76d55 100644 --- a/Desafio_10.ipynb +++ b/Desafio_10.ipynb @@ -1,87 +1,96 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_10.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyN/VxX3vX37Fphq4s0/I3Ia", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "a4-FLDRof6Jv" - }, - "source": [ - "### Desafio 10\n", - "\n", - "Dada uma lista, divida-a em 3 partes iguais e reverta a ordem de cada lista.\n", - "\n", - "**Exemplo:** \n", - "\n", - "Entrada: \\\n", - "sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]\n", - "\n", - "Saída: \\\n", - "Parte 1 [8, 45, 11] \\\n", - "Parte 2 [12, 14, 23] \\\n", - "Parte 3 [89, 45, 78] " - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "IJ70pUjnf6Jw" - }, - "outputs": [], - "source": [ - "# Seu código" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "pNrXNVqf8Wc1" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 10.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NX3x0OcS0rPv" + }, + "source": [ + "Dada uma lista, divida-a em 3 partes iguais e reverta a ordem de cada lista.\n", + "\n", + "Exemplo:\n", + "\n", + "Entrada: \\ sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]\n", + "\n", + "Saída: \\ Parte 1 [8, 45, 11] \\ Parte 2 [12, 14, 23] \\ Parte 3 [89, 45, 78]" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "RnuokNPz0qj1" + }, + "source": [ + "#lista\n", + "sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]" + ], + "execution_count": 11, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "u8x_ORVC1-wO", + "outputId": "3f3b7766-d97e-44e2-d447-0722b5911d83" + }, + "source": [ + "partes = 3 #número de partes da lista\n", + "newList = [] #Criando a nova lista\n", + "\n", + "#Range vai permitir que o for execute de 0 a 9 a cada 3 passos, ou seja, criará 3 listas. \n", + "for i in range(0, len(sampleList), partes):\n", + "# Na primeira interação adiciono os elementos de 0:3 de forma inversa\n", + " newList.append(sampleList[i:i+partes][::-1])\n", + "\n", + "newList\n", + "\n" + ], + "execution_count": 79, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[[8, 45, 11], [12, 14, 23], [89, 45, 78]]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 79 + } + ] + } + ] +} \ No newline at end of file From 473f6277a3a2421b9c4cedbed8ded597e37610d7 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Sun, 23 May 2021 23:26:27 -0300 Subject: [PATCH 12/16] Criado usando o Colaboratory --- Desafio_11.ipynb | 166 +++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/Desafio_11.ipynb b/Desafio_11.ipynb index b6a8536..485166c 100644 --- a/Desafio_11.ipynb +++ b/Desafio_11.ipynb @@ -1,85 +1,85 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_11.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyOba2cSixn2P4ZVebTJa13X", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "y1R0m4oWf6Jz" - }, - "source": [ - "### Desafio 8\n", - "Dados uma sequência com `n` números inteiros, determinar quantos números da sequência são pares e quantos são ímpares.\\\n", - "Por exemplo, para a sequência\n", - "\n", - "`6 2 7 -5 8 -4`\n", - "\n", - "a sua função deve retornar o número 4 para o número de pares e 2 para o de ímpares.\\\n", - "A saída deve ser um **tupla** contendo primeiramente o número de pares e em seguida o número de ímpares.\\\n", - "Para o exemplo anterior, a saída seria `(4, 2)`." - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "pSIzX4zUf6Jz" - }, - "outputs": [], - "source": [ - "# Seu código\n", - "def contar_pares_impares(entrada):\n", - " pass" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "OQG6erslSjri" - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 11.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7Hdo34V0IF_0" + }, + "source": [ + "Dados uma sequência com n números inteiros, determinar quantos números da sequência são pares e quantos são ímpares.\\ Por exemplo, para a sequência\n", + "\n", + "6 2 7 -5 8 -4\n", + "\n", + "a sua função deve retornar o número 4 para o número de pares e 2 para o de ímpares.\\ A saída deve ser um tupla contendo primeiramente o número de pares e em seguida o número de ímpares.\\ Para o exemplo anterior, a saída seria (4, 2).\n", + "\n", + "def contar_pares_impares(entrada):\n", + " pass" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "K6NcSXK4IBei", + "outputId": "6aa32750-f5be-47ff-d558-c66c72ad1bf5" + }, + "source": [ + "#Lista de valores\n", + "valores = [6,2,7,-5,8,-4]\n", + "contagem = []\n", + "def contar_pares_impares(entrada):\n", + " for i in valores:\n", + "#Verificando se o valor é parte ou impar\n", + " if i % 2==0:\n", + " contagem.append(\"par\")\n", + " else:\n", + " contagem.append(\"impar\")\n", + "\n", + "contar_pares_impares(valores) \n", + "#criando uma tupla com a quantidade de valores pares e impares\n", + "tupla = (contagem.count(\"par\"), contagem.count(\"impar\"))\n", + "print(tupla)" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(4, 2)\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 1f6d25d5ee3996323ad8e3875ebf6ca2be7a8c14 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Mon, 24 May 2021 19:27:49 -0300 Subject: [PATCH 13/16] Criado usando o Colaboratory --- Desafio_01.ipynb | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/Desafio_01.ipynb b/Desafio_01.ipynb index f529c11..b500d2d 100644 --- a/Desafio_01.ipynb +++ b/Desafio_01.ipynb @@ -5,7 +5,8 @@ "colab": { "name": "Desafio_01.ipynb", "provenance": [], - "authorship_tag": "ABX9TyNmwryVGQoS6/AS74yzoTFf", + "collapsed_sections": [], + "authorship_tag": "ABX9TyPQqjWtYWlcduMB6RqsSfWy", "include_colab_link": true }, "kernelspec": { @@ -50,7 +51,7 @@ " 'white', 'orange', \"orange\", 'red'\n", "]" ], - "execution_count": 2, + "execution_count": 3, "outputs": [] }, { @@ -66,7 +67,7 @@ "#Quantidade de elementos total na minha lista\n", "len(palavras)" ], - "execution_count": 4, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -99,7 +100,7 @@ "for i in distinto:\n", " print(f\"{i}, aparece na lista {palavras.count(i)} vezes\")" ], - "execution_count": 24, + "execution_count": null, "outputs": [ { "output_type": "stream", @@ -115,6 +116,43 @@ "name": "stdout" } ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "gnh6QkNIevRq", + "outputId": "5e975241-bb31-4bd4-c235-514d9e87e52c" + }, + "source": [ + "#Segunda forma\n", + "palavras_unicas = set(palavras)\n", + "ocorrencias = {palavra: palavras.count(palavra) for palavra in palavras_unicas}\n", + "ocorrencias" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{'black': 5,\n", + " 'eyes': 1,\n", + " 'green': 4,\n", + " 'orange': 4,\n", + " 'pink': 6,\n", + " 'red': 4,\n", + " 'white': 5}" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 5 + } + ] } ] } \ No newline at end of file From 5de8ba49fa6f8ad8c16cfc63729bc5a6b3d711a6 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Mon, 24 May 2021 19:31:26 -0300 Subject: [PATCH 14/16] Criado usando o Colaboratory --- Desafio_03.ipynb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Desafio_03.ipynb b/Desafio_03.ipynb index 215ee23..626a96d 100644 --- a/Desafio_03.ipynb +++ b/Desafio_03.ipynb @@ -5,7 +5,8 @@ "colab": { "name": "Desafio_03.ipynb", "provenance": [], - "authorship_tag": "ABX9TyPOg1AALwmQJ/qUARKwMvue", + "collapsed_sections": [], + "authorship_tag": "ABX9TyNPXGcTGCuiVUXq/yNs6KsT", "include_colab_link": true }, "kernelspec": { @@ -45,7 +46,7 @@ "#Lista de valores\n", "lista = [1,2,3,4,3,30,3,4,5,6,9,3,2,1,2,4,5,15,6,6,3,13,4,45,5]" ], - "execution_count": 1, + "execution_count": 2, "outputs": [] }, { @@ -55,12 +56,15 @@ "base_uri": "https://localhost:8080/" }, "id": "S__igKuDaton", - "outputId": "72f99c50-fdde-48ea-ef62-c0481d67fdf9" + "outputId": "c9e9df99-8870-4a60-8eb2-e580fefb49cc" }, "source": [ "#Lista com valores únicos e ordenados\n", - "lista_unica = sorted(set(lista))\n", - "print(lista_unica)" + "def lista_unica(lista):\n", + " lista_unica = sorted(set(lista))\n", + " print(lista_unica)\n", + "\n", + "lista_unica(lista)" ], "execution_count": 3, "outputs": [ From 8d73d9db20d8554651ea81e40d8bac49ca4fbd1a Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Mon, 24 May 2021 19:48:29 -0300 Subject: [PATCH 15/16] Criado usando o Colaboratory --- Desafio_06.ipynb | 89 +++++------------------------------------------- 1 file changed, 8 insertions(+), 81 deletions(-) diff --git a/Desafio_06.ipynb b/Desafio_06.ipynb index 37c8e8f..6dff53c 100644 --- a/Desafio_06.ipynb +++ b/Desafio_06.ipynb @@ -6,7 +6,7 @@ "name": "Desafio_06.ipynb", "provenance": [], "collapsed_sections": [], - "authorship_tag": "ABX9TyPrEpup1RZFJzW5wL62cTLn", + "authorship_tag": "ABX9TyPo7EG07MlyPqG/wvbU2QYB", "include_colab_link": true }, "kernelspec": { @@ -46,7 +46,7 @@ "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]" ], - "execution_count": 28, + "execution_count": 1, "outputs": [] }, { @@ -56,102 +56,29 @@ "base_uri": "https://localhost:8080/" }, "id": "yXpMJtD0ZpXj", - "outputId": "255ebac5-51e6-4805-df77-2cc412fa36dd" + "outputId": "410dae6a-601d-4a3e-d5e2-b2f1af9299b0" }, "source": [ "#Forma mais simples\n", "def listaUnica(a,b):\n", - " resultado = set(a + b)\n", - " return resultado\n", + " resultado = set(a).intersection(b)\n", + " return list(resultado)\n", "\n", "listaUnica(a,b)\n" ], - "execution_count": 54, + "execution_count": 7, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ - "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 21, 34, 55, 89}" + "[1, 2, 3, 5, 8, 13]" ] }, "metadata": { "tags": [] }, - "execution_count": 54 - } - ] - }, - { - "cell_type": "code", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "uQX9mFXORGnh", - "outputId": "223b1b68-0394-4d54-caa9-127b00a01959" - }, - "source": [ - "#Utilizando for mais função itertools\n", - "\n", - "def juncaoListas(a,b):\n", - " #importando a Biblioteca itertools\n", - " import itertools\n", - " #Criando as listas auxiliares\n", - " novaLista = []\n", - " listaUnica = []\n", - " #Chamando a função zip_longest da biblioteca itertools\n", - " for i,j in itertools.zip_longest(a,b, fillvalue=a[0]):\n", - " #Adicionando os elementos à lista\n", - " novaLista.append(i)\n", - " novaLista.append(j)\n", - " #Criando a lista única\n", - " listaUnica = set(novaLista)\n", - " print(listaUnica)\n", - "\n", - "juncaoListas(a,b)\n" - ], - "execution_count": 43, - "outputs": [ - { - "output_type": "stream", - "text": [ - "{1, 2, 3, 4, 5, 6, 7, 8, 34, 9, 10, 11, 13, 12, 21, 55, 89}\n" - ], - "name": "stdout" - } - ] - }, - { - "cell_type": "code", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "zLo6r4jtYt6y", - "outputId": "a1681fb1-19f6-4f5f-d1d3-6ee5ce8ce289" - }, - "source": [ - "#Segunda Forma com muitas iterações\n", - "\n", - "def niteracoes(a,b):\n", - " lista3 = []\n", - " for i in a:\n", - " for j in b:\n", - " lista3.append(j)\n", - " lista3.append(i)\n", - " print(set(lista3))\n", - "\n", - "niteracoes(a,b)\n" - ], - "execution_count": 53, - "outputs": [ - { - "output_type": "stream", - "text": [ - "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 21, 55, 89}\n" - ], - "name": "stdout" + "execution_count": 7 } ] } From 76e384404e5da6a1cbc8bd451ccc97558c4da560 Mon Sep 17 00:00:00 2001 From: Mateus Carvalho Date: Thu, 10 Jun 2021 12:36:38 -0300 Subject: [PATCH 16/16] Criado usando o Colaboratory --- Desafio_12.ipynb | 204 ++++++++++++++++++++++++++++------------------- 1 file changed, 123 insertions(+), 81 deletions(-) diff --git a/Desafio_12.ipynb b/Desafio_12.ipynb index 32aacf3..0ea4a00 100644 --- a/Desafio_12.ipynb +++ b/Desafio_12.ipynb @@ -1,83 +1,125 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "![](https://i.imgur.com/YX6UATs.png)" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Desafio_12.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyN5+FrjznV+8rjnXvIrC1eL", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "AYHY2YXQf6J2" - }, - "source": [ - "### Desafio 12\n", - "\n", - "Escreva uma função em Python para verificar a validade de uma senha.\n", - "\n", - "A senha deve ter:\n", - "\n", - "* Pelo menos 1 letra entre [a-z] e 1 letra entre [A-Z].\n", - "* Pelo menos 1 número entre [0-9].\n", - "* Pelo menos 1 caractere de [$ # @].\n", - "* Comprimento mínimo de 6 caracteres.\n", - "* Comprimento máximo de 16 caracteres.\n", - "\n", - "Entradas: \"12345678\", \"J3sus0\", \"#Te5t300\", \"J*90j12374\", \"Michheeul\", \"Monk3y6\"\n", - "\n", - "A saída deve ser a senha e um texto indicando se a senha é válida ou inválida:\n", - "\n", - "```\n", - "\"1234\" - Senha inválida\n", - "\"Qw#1234\" - Senha válida\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "UGgtGYGGf6J3" - }, - "outputs": [], - "source": [ - "# Seu código" - ] - } - ], - "metadata": { - "anaconda-cloud": {}, - "colab": { - "include_colab_link": true, - "name": "Desafio 12.ipynb", - "provenance": [] - }, - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gZ3S40YwMli8" + }, + "source": [ + "Escreva uma função em Python para verificar a validade de uma senha.\n", + "\n", + "A senha deve ter:\n", + "\n", + "* Pelo menos 1 letra entre [a-z] e 1 letra entre [A-Z].\n", + "* Pelo menos 1 número entre [0-9].\n", + "* Pelo menos 1 caractere de [$ # @].\n", + "* Comprimento mínimo de 6 caracteres.\n", + "* Comprimento máximo de 16 caracteres.\n", + "\n", + "* Entradas: \"12345678\", \"J3sus0\", \"#Te5t300\", \"J*90j12374\", \"Michheeul\", \"Monk3y6\"\n", + "\n", + "A saída deve ser a senha e um texto indicando se a senha é válida ou inválida:\n", + "\n", + "* \"1234\" - Senha inválida\n", + "* \"Qw#1234\" - Senha válida" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "JYqkT85gyC9K" + }, + "source": [ + "import re\n", + "\n", + "def verifica_senha(senha):\n", + " regras_regex = [\"[0-9]\", \"[a-z]\", \"[A-Z]\", \"[$#@]\"]\n", + " tamanho_max = 16\n", + " tamanho_min = 6\n", + " erros = []\n", + "\n", + " for validacao in regras_regex:\n", + " if len(re.findall(validacao,senha)) == 0:\n", + " erros.append(f\"Erro na senha {validacao}\")\n", + " if len(senha)<=tamanho_min:\n", + " erros.append(f\"A senha contém menos que 6 caracteres. Deve ter de 6 a 16 carcateres\")\n", + " if len(senha)>=tamanho_max:\n", + " erros.append(f\"A senha contém mais que 16 caracteres. Deve ter de 6 a 16 carcateres\")\n", + " if len(erros)>0:\n", + " print(erros)\n", + " return \"Senha invalida\"\n", + " else:\n", + " return \"Senha válida\"" + ], + "execution_count": 12, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "id": "UcRCpnmMjUyu", + "outputId": "144116bb-6b0b-4b18-c2b2-2da3c4a4a079" + }, + "source": [ + "verifica_senha(\"teste123@\")" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "text": [ + "['Erro na senha [A-Z]']\n" + ], + "name": "stdout" + }, + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'Senha invalida'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 16 + } + ] + } + ] +} \ No newline at end of file