From 35cac392925f8e9be32db720668115f173d32304 Mon Sep 17 00:00:00 2001 From: Paulo Santos <69723121+PauloViOS@users.noreply.github.com> Date: Mon, 3 May 2021 07:11:37 -0300 Subject: [PATCH] Adds solved challenges --- Desafio_01.ipynb | 67 ++++++++++--- Desafio_02.ipynb | 69 ++++++++++++- Desafio_03.ipynb | 78 ++++++++++++--- Desafio_04.ipynb | 51 +++++++++- Desafio_05.ipynb | 57 ++++++++++- Desafio_06.ipynb | 70 ++++++++++++-- Desafio_07.ipynb | 63 ++++++++++-- Desafio_08.ipynb | 245 ++++++++++++++++++++++++++++++++++++++++++++--- Desafio_09.ipynb | 35 +++++-- Desafio_10.ipynb | 32 ++++--- Desafio_11.ipynb | 36 +++++-- Desafio_12.ipynb | 49 +++++++++- 12 files changed, 758 insertions(+), 94 deletions(-) diff --git a/Desafio_01.ipynb b/Desafio_01.ipynb index db922b9..10a5a7b 100644 --- a/Desafio_01.ipynb +++ b/Desafio_01.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 41, "metadata": { "colab": {}, "colab_type": "code", @@ -37,20 +37,65 @@ " '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", + "]" + ] + }, + { + "source": [ + "### Considera cada palavra uma chave de um dicionário. Se a chave não existir, cria e atribui valor 1. Se existir, adiciona 1 ao valor da chave" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "def contagem(lista): \n", "\n", + " resultado = {}\n", "\n", - "# Seu código" + " for palavra in lista:\n", + " resultado[palavra] = resultado.get(palavra, 0) + 1\n", + " \n", + " resultado = dict(sorted(resultado.items(), key= lambda item: item[1]))\n", + "\n", + " return resultado\n", + " " ] }, { "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "M58o1U9KfAxa" - }, + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{'eyes': 1,\n", + " 'red': 4,\n", + " 'green': 4,\n", + " 'orange': 4,\n", + " 'black': 5,\n", + " 'white': 5,\n", + " 'pink': 6}" + ] + }, + "metadata": {}, + "execution_count": 43 + } + ], + "source": [ + "contagem(palavras)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], "source": [] } @@ -77,9 +122,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_02.ipynb b/Desafio_02.ipynb index 8aa2264..2c429dc 100644 --- a/Desafio_02.ipynb +++ b/Desafio_02.ipynb @@ -29,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 1, "metadata": { "colab": {}, "colab_type": "code", @@ -38,7 +38,68 @@ "outputs": [], "source": [ "def convert_to_sec(number):\n", - " pass # Seu código" + " \n", + " return number*3600" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "18000" + ] + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "convert_to_sec(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "10800" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "convert_to_sec(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "7200" + ] + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "convert_to_sec(2)" ] } ], @@ -64,9 +125,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_03.ipynb b/Desafio_03.ipynb index 75be003..6631fac 100644 --- a/Desafio_03.ipynb +++ b/Desafio_03.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 13, "metadata": { "colab": {}, "colab_type": "code", @@ -32,21 +32,73 @@ }, "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" + "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]" ] }, { "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "wo2rA-NriFtO" - }, + "execution_count": 14, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def arruma_lista(lista):\n", + " \n", + " lista.sort()\n", + "\n", + " numero_anterior = lista[0]\n", + "\n", + " for numero in lista[1:]:\n", + " if numero == numero_anterior:\n", + " lista.pop(numero)\n", + " else:\n", + " numero_anterior = numero\n", + "\n", + " return lista" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6, 9, 13, 15, 30, 45]" + ] + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "arruma_lista(lista)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6, 9, 13, 15, 30, 45]" + ] + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "#Maneira sintética\n", + "def arruma_lista_sintetico(lista):\n", + " return sorted(set(lista))\n", + "\n", + "arruma_lista_sintetico(lista)" + ] } ], "metadata": { @@ -71,9 +123,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_04.ipynb b/Desafio_04.ipynb index bdab516..2a2e0d9 100644 --- a/Desafio_04.ipynb +++ b/Desafio_04.ipynb @@ -28,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 5, "metadata": { "colab": {}, "colab_type": "code", @@ -36,7 +36,50 @@ }, "outputs": [], "source": [ - "# Seu código" + "def inverte_texto(frase):\n", + " \n", + " return ' '.join(frase.split()[::-1])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'legal é Python'" + ] + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "inverte_texto(\"Python é legal\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'Roma de rei do roupa a roeu rato O'" + ] + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "inverte_texto(\"O rato roeu a roupa do rei de Roma\")" ] } ], @@ -62,9 +105,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_05.ipynb b/Desafio_05.ipynb index 0794a31..9e9cb83 100644 --- a/Desafio_05.ipynb +++ b/Desafio_05.ipynb @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 17, "metadata": { "colab": {}, "colab_type": "code", @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 18, "metadata": { "colab": {}, "colab_type": "code", @@ -67,7 +67,54 @@ }, "outputs": [], "source": [ - "#Seu código" + "def arruma_lista(lista):\n", + " \n", + " lista.sort()\n", + "\n", + " numero_anterior = lista[0]\n", + "\n", + " for numero in lista[1::]:\n", + " if numero == numero_anterior:\n", + " lista.remove(numero)\n", + " else:\n", + " numero_anterior = numero\n", + "\n", + " print(*lista, sep='\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(255) 826-9050\n(285) 608-2448\n(311) 799-3883\n(410) 665-4447\n(464) 788-2397\n(511) 821-7870\n(554) 994-1517\n(596) 336-5508\n(650) 684-1437\n(765) 368-1506\n(812) 816-0881\n(821) 642-8987\n(885) 407-1719\n(935) 875-2054\n(943) 769-1061\n" + ] + } + ], + "source": [ + "arruma_lista(numeros_telefone)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(255) 826-9050\n(285) 608-2448\n(311) 799-3883\n(410) 665-4447\n(464) 788-2397\n(511) 821-7870\n(554) 994-1517\n(596) 336-5508\n(650) 684-1437\n(765) 368-1506\n(812) 816-0881\n(821) 642-8987\n(885) 407-1719\n(935) 875-2054\n(943) 769-1061\n" + ] + } + ], + "source": [ + "#jeito fácil em uma linha\n", + "print(*sorted(set(numeros_telefone)), sep=\"\\n\")" ] } ], @@ -93,9 +140,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_06.ipynb b/Desafio_06.ipynb index 1381088..f96df23 100644 --- a/Desafio_06.ipynb +++ b/Desafio_06.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 6, "metadata": { "colab": {}, "colab_type": "code", @@ -49,17 +49,75 @@ }, "outputs": [], "source": [ - "# Seu código" + "def intersecao(lista_1,lista_2):\n", + " \n", + " lista_1.extend(lista_2)\n", + " \n", + " lista_1.sort()\n", + " \n", + " numero_anterior = lista_1[0]\n", + "\n", + " for numero in lista_1[1::]:\n", + " if numero == numero_anterior:\n", + " lista_1.pop(numero)\n", + " else:\n", + " numero_anterior = numero\n", + "\n", + " return lista_1" ] }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 7, "metadata": { "colab": {}, "colab_type": "code", "id": "ly-N_Aq624RQ" }, + "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": {}, + "execution_count": 7 + } + ], + "source": [ + "intersecao(a,b)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "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": {}, + "execution_count": 8 + } + ], + "source": [ + "# Jeito sintético\n", + "def intersecao_sintetica(a, b):\n", + " return sorted(set(a + b))\n", + "\n", + "intersecao_sintetica(a, b)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], "source": [] } @@ -86,9 +144,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_07.ipynb b/Desafio_07.ipynb index 55c90e7..51888f4 100644 --- a/Desafio_07.ipynb +++ b/Desafio_07.ipynb @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 11, "metadata": { "colab": {}, "colab_type": "code", @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 12, "metadata": { "colab": {}, "colab_type": "code", @@ -90,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 13, "metadata": { "colab": {}, "colab_type": "code", @@ -98,8 +98,59 @@ }, "outputs": [], "source": [ - "#Seu código." + "def nao_entraram(lista_todos, lista_entraram):\n", + "\n", + " nao_entraram=[]\n", + " \n", + " for numero in lista_todos:\n", + " if numero not in lista_entraram:\n", + " nao_entraram.append(numero)\n", + " \n", + " print(*sorted(nao_entraram), sep=\"\\n\")" ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(294) 430-7720\n(300) 303-5462\n(403) 343-7705\n(491) 666-5367\n(640) 427-2597\n(641) 367-5279\n(757) 450-9985\n(797) 649-3653\n(835) 955-1498\n(856) 338-7094\n(873) 810-8267\n(897) 932-2512\n(941) 225-3869\n(964) 710-9625\n" + ] + } + ], + "source": [ + "nao_entraram(telefones_alunos, entraram_no_grupo)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(294) 430-7720\n(300) 303-5462\n(403) 343-7705\n(491) 666-5367\n(640) 427-2597\n(641) 367-5279\n(757) 450-9985\n(797) 649-3653\n(835) 955-1498\n(856) 338-7094\n(873) 810-8267\n(897) 932-2512\n(941) 225-3869\n(964) 710-9625\n" + ] + } + ], + "source": [ + "#exatamente a mesma coisa com list comprehension (acho muito mais legível e não cria uma lista desnecessária)\n", + "\n", + "print(*sorted([numero for numero in telefones_alunos if numero not in entraram_no_grupo]), sep='\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -124,9 +175,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_08.ipynb b/Desafio_08.ipynb index de5d802..7d12f51 100644 --- a/Desafio_08.ipynb +++ b/Desafio_08.ipynb @@ -24,26 +24,243 @@ ] }, { - "cell_type": "code", - "execution_count": 0, + "source": [ + "### Abre e lê arquivo de texto" + ], + "cell_type": "markdown", "metadata": { "colab": {}, "colab_type": "code", - "id": "EknxjSG0f6Jo" - }, - "outputs": [], + "id": "ZYbqEWBG5nKx" + } + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'What is Python language? \\nPython 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 \\nlanguages such as C++ or Java. \\nPython 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": {}, + "execution_count": 9 + } + ], "source": [ - "# Seu código" + "texto = open(\"texto.txt\", \"r\").read()\n", + "\n", + "texto" ] }, + { + "source": [ + "### Remove símbolos não pertencentes a palavras e os substitui por um espaço vazio" + ], + "cell_type": "markdown", + "metadata": {} + }, { "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "ZYbqEWBG5nKx" - }, + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'What is Python language 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 languages such as C++ or Java 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": {}, + "execution_count": 10 + } + ], + "source": [ + "for simbolo in \",.)(?\\n\":\n", + " texto = texto.replace(simbolo, ' ')\n", + "\n", + "texto" + ] + }, + { + "source": [ + "### Designa cada palavra como um item de uma lista e os ordena em ordem inversa de tamanho" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['general-purpose',\n", + " 'object-oriented',\n", + " 'comprehensive',\n", + " 'intermediate',\n", + " 'interpreted',\n", + " 'programming',\n", + " 'readability',\n", + " 'programmers',\n", + " 'programming',\n", + " 'programming',\n", + " 'high-level',\n", + " 'philosophy',\n", + " 'emphasizes',\n", + " 'imperative',\n", + " 'functional',\n", + " 'procedural',\n", + " 'management',\n", + " 'languages',\n", + " 'paradigms',\n", + " 'including',\n", + " 'automatic',\n", + " 'questions',\n", + " 'language',\n", + " 'language',\n", + " 'concepts',\n", + " 'possible',\n", + " 'supports',\n", + " 'multiple',\n", + " 'features',\n", + " 'standard',\n", + " 'anything',\n", + " 'practice',\n", + " 'exercise',\n", + " 'beginner',\n", + " 'familiar',\n", + " 'dynamic',\n", + " 'express',\n", + " 'dynamic',\n", + " 'library',\n", + " 'started',\n", + " 'section',\n", + " 'Python',\n", + " 'Python',\n", + " 'widely',\n", + " 'design',\n", + " 'syntax',\n", + " 'allows',\n", + " 'Python',\n", + " 'styles',\n", + " 'system',\n", + " 'memory',\n", + " 'Python',\n", + " 'fewer',\n", + " 'lines',\n", + " 'large',\n", + " 'learn',\n", + " 'those',\n", + " 'What',\n", + " 'used',\n", + " 'code',\n", + " 'code',\n", + " 'than',\n", + " 'such',\n", + " 'Java',\n", + " 'type',\n", + " 'best',\n", + " 'have',\n", + " 'this',\n", + " 'with',\n", + " 'Its',\n", + " 'and',\n", + " 'its',\n", + " 'C++',\n", + " 'and',\n", + " 'and',\n", + " 'and',\n", + " 'has',\n", + " 'and',\n", + " 'The',\n", + " 'way',\n", + " 'and',\n", + " 'for',\n", + " 'who',\n", + " 'are',\n", + " 'is',\n", + " 'is',\n", + " 'to',\n", + " 'in',\n", + " 'of',\n", + " 'in',\n", + " 'as',\n", + " 'or',\n", + " 'or',\n", + " 'It',\n", + " 'we',\n", + " 'is',\n", + " 'by',\n", + " 'We',\n", + " 'to',\n", + " 'a',\n", + " 'a',\n", + " 'a']" + ] + }, + "metadata": {}, + "execution_count": 11 + } + ], + "source": [ + "lista_de_palavras = texto.split()\n", + "\n", + "def tamanho(x):\n", + " return len(x)\n", + "\n", + "lista_de_palavras.sort(key=tamanho, reverse=True)\n", + "\n", + "lista_de_palavras" + ] + }, + { + "source": [ + "### Lista 10 maiores palavras em ordem crescente sem repetição" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Maiores palavras: \n1ª - general-purpose\n2ª - object-oriented\n3ª - comprehensive\n4ª - intermediate\n5ª - interpreted\n6ª - programming\n7ª - readability\n8ª - programmers\n9ª - high-level\n10ª - philosophy\n" + ] + } + ], + "source": [ + "maiores_palavras =[]\n", + "contador = 0\n", + "\n", + "while len(maiores_palavras)<10:\n", + " if lista_de_palavras[contador] not in maiores_palavras:\n", + " maiores_palavras.append(lista_de_palavras[contador])\n", + " else:\n", + " contador += 1\n", + "\n", + "print(\"Maiores palavras: \")\n", + "\n", + "for x in range(0,10):\n", + " print(f'{x+1}ª - {maiores_palavras[x]}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], "source": [] } @@ -70,9 +287,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_09.ipynb b/Desafio_09.ipynb index 6fb29e1..5ae7912 100644 --- a/Desafio_09.ipynb +++ b/Desafio_09.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 1, "metadata": { "colab": {}, "colab_type": "code", @@ -33,19 +33,40 @@ }, "outputs": [], "source": [ - "# Seu código" + "def soma_estranha(limite):\n", + "\n", + " multiplos_3 = [n for n in range(3, limite + 1, 3)]\n", + " print(f'Múltiplos de 3: {multiplos_3}\\n')\n", + " \n", + " multiplos_5 = [n for n in range(5, limite + 1, 5)]\n", + " print(f'Múltiplos de 5: {multiplos_5}\\n')\n", + " \n", + " lista_completa = list(set(multiplos_3 + multiplos_5))\n", + " print(f'Todos juntos: {lista_completa}\\n')\n", + " \n", + " print(f'Soma de todos os múltiplos: {sum(lista_completa)}')" ] }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 2, "metadata": { "colab": {}, "colab_type": "code", "id": "a_6aqcKp6wrN" }, - "outputs": [], - "source": [] + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Múltiplos de 3: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39]\n\nMúltiplos de 5: [5, 10, 15, 20, 25, 30, 35, 40]\n\nTodos juntos: [3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30, 33, 35, 36, 39, 40]\n\nSoma de todos os múltiplos: 408\n" + ] + } + ], + "source": [ + "soma_estranha(40)" + ] } ], "metadata": { @@ -70,9 +91,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_10.ipynb b/Desafio_10.ipynb index 4f831f3..57e7e6a 100644 --- a/Desafio_10.ipynb +++ b/Desafio_10.ipynb @@ -34,25 +34,35 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 2, "metadata": { "colab": {}, "colab_type": "code", "id": "IJ70pUjnf6Jw" }, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Parte 1 [8, 45, 11]\nParte 2 [12, 14, 23]\nParte 3 [45, 78]\n" + ] + } + ], "source": [ - "# Seu código" + "def divrev(lst):\n", + " \n", + " for i in range(0, len(lst), 3):\n", + " print (f'Parte {i//3+1} {lst[i:i+3][::-1]}')\n", + "\n", + "\n", + "divrev([11, 45, 8, 23, 14, 12, 78, 45])" ] }, { "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "pNrXNVqf8Wc1" - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [] } @@ -79,9 +89,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_11.ipynb b/Desafio_11.ipynb index b6a8536..95aa0e7 100644 --- a/Desafio_11.ipynb +++ b/Desafio_11.ipynb @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 8, "metadata": { "colab": {}, "colab_type": "code", @@ -38,21 +38,39 @@ }, "outputs": [], "source": [ - "# Seu código\n", - "def contar_pares_impares(entrada):\n", - " pass" + "def contar_pares_impares(*args):\n", + " \n", + " lista = [0,0]\n", + " \n", + " for numero in args:\n", + " if numero%2 == 0:\n", + " lista[0] += 1\n", + " else:\n", + " lista[1] += 1\n", + " \n", + " print(tuple(lista))" ] }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 9, "metadata": { "colab": {}, "colab_type": "code", "id": "OQG6erslSjri" }, - "outputs": [], - "source": [] + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(4, 2)\n" + ] + } + ], + "source": [ + "contar_pares_impares(6,2,7,-5,8,-4)" + ] } ], "metadata": { @@ -77,9 +95,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file diff --git a/Desafio_12.ipynb b/Desafio_12.ipynb index 32aacf3..2dc4be4 100644 --- a/Desafio_12.ipynb +++ b/Desafio_12.ipynb @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": 5, "metadata": { "colab": {}, "colab_type": "code", @@ -49,8 +49,49 @@ }, "outputs": [], "source": [ - "# Seu código" + "#com regex\n", + "import re\n", + "\n", + "def validasenha(senha):\n", + " x = re.search(\"[a-zA-Z]\", senha)\n", + " y = re.search(\"[0-9]\", senha)\n", + " z = re.search(\"[$#@]\", senha)\n", + " w = 6 <= len(senha) <= 16\n", + "\n", + " if None not in (x, y, z) and w == True :\n", + " print(f'{senha} - Senha válida')\n", + " else:\n", + " print(f'{senha} - Senha inválida')\n" ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "12345678 - Senha inválida\nJ3sus0 - Senha inválida\n#Te5t300 - Senha válida\nJ*90j12374 - Senha inválida\nMichheeul - Senha inválida\nMonk3y6 - Senha inválida\n" + ] + } + ], + "source": [ + "validasenha(\"12345678\")\n", + "validasenha(\"J3sus0\")\n", + "validasenha(\"#Te5t300\")\n", + "validasenha(\"J*90j12374\")\n", + "validasenha(\"Michheeul\")\n", + "validasenha(\"Monk3y6\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -75,9 +116,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 -} +} \ No newline at end of file