diff --git a/Desafio_01.ipynb b/Desafio_01.ipynb
index 49ee4db..e5d8401 100644
--- a/Desafio_01.ipynb
+++ b/Desafio_01.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -57,17 +57,15 @@
"colab": {}
},
"source": [
+ "# Solução via Data Frame\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",
- "]\n",
- "\n",
- "\n",
- "# Seu código"
+ "]\n"
],
- "execution_count": 0,
+ "execution_count": 17,
"outputs": []
},
{
@@ -78,10 +76,196 @@
"colab": {}
},
"source": [
- ""
+ "import numpy as np\n",
+ "import pandas as pd"
],
- "execution_count": 0,
+ "execution_count": 18,
"outputs": []
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "k1u6Ft_XE3W9",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 266
+ },
+ "outputId": "9f1b5ce8-d148-40bc-ed94-9235e2fb873a"
+ },
+ "source": [
+ "df = pd.DataFrame({'cor':palavras})\n",
+ "df['num'] = 1\n",
+ "df2 = df.groupby(['cor'],as_index=False).agg({'num':'count'}).sort_values(['num'],ascending=False)\n",
+ "df2"
+ ],
+ "execution_count": 19,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " cor | \n",
+ " num | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 4 | \n",
+ " pink | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | 0 | \n",
+ " black | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " white | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " green | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " orange | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " red | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " eyes | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " cor num\n",
+ "4 pink 6\n",
+ "0 black 5\n",
+ "6 white 5\n",
+ "2 green 4\n",
+ "3 orange 4\n",
+ "5 red 4\n",
+ "1 eyes 1"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 19
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "4FuxyViJ55-g",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 136
+ },
+ "outputId": "fffd92b0-c17a-4dad-97b9-b91c1c59ed36"
+ },
+ "source": [
+ "# Solução via set\n",
+ "palavras_set = set(palavras)\n",
+ "palavras_set\n",
+ "for i in palavras_set:\n",
+ " print(i,palavras.count(i))"
+ ],
+ "execution_count": 20,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "green 4\n",
+ "black 5\n",
+ "orange 4\n",
+ "red 4\n",
+ "white 5\n",
+ "pink 6\n",
+ "eyes 1\n"
+ ],
+ "name": "stdout"
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "sq_6g4FD1guf",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 136
+ },
+ "outputId": "856311b3-5935-468c-b9ad-441d335e9092"
+ },
+ "source": [
+ "# Solução via RE\n",
+ "import re\n",
+ "\n",
+ "my_string = 'red green black pink black white black eyes white black orange pink pink red red white orange white black pink green green pink green pink white orange orange red'\n",
+ "\n",
+ "words = re.findall(r'\\w+', my_string)\n",
+ "from collections import Counter\n",
+ "\n",
+ "cap_words = [word.upper() for word in words] #capitalizes all the words\n",
+ "\n",
+ "word_counts = Counter(cap_words)\n",
+ "word_counts"
+ ],
+ "execution_count": 21,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "Counter({'BLACK': 5,\n",
+ " 'EYES': 1,\n",
+ " 'GREEN': 4,\n",
+ " 'ORANGE': 4,\n",
+ " 'PINK': 6,\n",
+ " 'RED': 4,\n",
+ " 'WHITE': 5})"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 21
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_02.ipynb b/Desafio_02.ipynb
index ee7f64b..2be7041 100644
--- a/Desafio_02.ipynb
+++ b/Desafio_02.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -68,8 +68,39 @@
"def convert_to_sec(number):\n",
" pass # Seu código"
],
- "execution_count": 0,
+ "execution_count": null,
"outputs": []
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "3MzoZgJJIh9V",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 51
+ },
+ "outputId": "bf56533f-62cb-4c92-c555-467abd0b3b27"
+ },
+ "source": [
+ "def convert_to_seconds(t):\n",
+ " seconds = t * 3600\n",
+ " return seconds\n",
+ "hours = int(input('How many hours do you want to convert into seconds? '))\n",
+ "\n",
+ "print(convert_to_seconds(hours))"
+ ],
+ "execution_count": 5,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "How many hours do you want to convert into seconds? 10\n",
+ "36000\n"
+ ],
+ "name": "stdout"
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_03.ipynb b/Desafio_03.ipynb
index 1311cbd..034041b 100644
--- a/Desafio_03.ipynb
+++ b/Desafio_03.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -57,11 +57,10 @@
"colab": {}
},
"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"
+ "# Usando o unique\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]\n"
],
- "execution_count": 0,
+ "execution_count": 1,
"outputs": []
},
{
@@ -69,13 +68,84 @@
"metadata": {
"id": "wo2rA-NriFtO",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "ec7f1a7f-ae06-41b3-94ae-d61de535a349"
},
"source": [
- ""
+ "import numpy as np\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]\n",
+ "print(np.unique(lista))"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 2,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "[ 1 2 3 4 5 6 9 13 15 30 45]\n"
+ ],
+ "name": "stdout"
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "7yqVCMcfJXXi",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "966601f4-080a-4ca2-db27-703b1dbcb11a"
+ },
+ "source": [
+ "print(-np.sort(-np.unique(lista)))"
+ ],
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "[45 30 15 13 9 6 5 4 3 2 1]\n"
+ ],
+ "name": "stdout"
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "EuqyYQg_75Ug",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "df1c3cc1-82f5-4923-f837-f8d4e562bb70"
+ },
+ "source": [
+ "# Usando o set\n",
+ "lista_set = set(lista)\n",
+ "lista_set\n"
+ ],
+ "execution_count": 7,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "{1, 2, 3, 4, 5, 6, 9, 13, 15, 30, 45}"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 7
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_04.ipynb b/Desafio_04.ipynb
index 089c3a8..a63eb9d 100644
--- a/Desafio_04.ipynb
+++ b/Desafio_04.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -58,26 +58,40 @@
"metadata": {
"id": "I5TInJDaf6JW",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 35
+ },
+ "outputId": "27992a7d-a31d-4ba5-d173-e3704192be1d"
},
"source": [
- "# Seu código"
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "cell_type": "code",
- "metadata": {
- "id": "6gq9SLl1xSV1",
- "colab_type": "code",
- "colab": {}
- },
- "source": [
- ""
+ "frase = ' Python é legal'\n",
+ "def inverte_texto(frase):\n",
+ " quebrada = frase.split()\n",
+ " invertida = quebrada[::-1]\n",
+ " final = ' '.join(invertida)\n",
+ " return final\n",
+ "\n",
+ "inverte_texto(frase)"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 2,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "string"
+ },
+ "text/plain": [
+ "'legal é Python'"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 2
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_05.ipynb b/Desafio_05.ipynb
index 204b1df..7a03f40 100644
--- a/Desafio_05.ipynb
+++ b/Desafio_05.ipynb
@@ -5,7 +5,6 @@
"colab": {
"name": "Desafio 5.ipynb",
"provenance": [],
- "authorship_tag": "ABX9TyO0u4amKtoFgAgnb/IGUddy",
"include_colab_link": true
},
"kernelspec": {
@@ -21,7 +20,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -68,7 +67,7 @@
"'(255) 826-9050',\n",
"]"
],
- "execution_count": 0,
+ "execution_count": 1,
"outputs": []
},
{
@@ -86,13 +85,186 @@
"metadata": {
"id": "F8n1sN-4XrW3",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 272
+ },
+ "outputId": "98a20d1e-885e-4919-866d-d91d76c1eb88"
},
"source": [
- ""
+ "# Solução com set\n",
+ "lsita_sem_duplicados = set(numeros_telefone)\n",
+ "lsita_sem_duplicados"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "{'(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'}"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 3
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "eE8kj1LaSJJJ",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 514
+ },
+ "outputId": "5d88f2ad-1167-4413-ad16-05d87a53c49c"
+ },
+ "source": [
+ "# Solução com Data Frame\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "\n",
+ "df = pd.DataFrame({'numeros_telefone':numeros_telefone})\n",
+ "df['num'] = 1\n",
+ "df2 = df.groupby(['numeros_telefone'],as_index=False).agg({'num':'count'}).sort_values(['num'],ascending=False)\n",
+ "df3 = df2[['numeros_telefone']].reset_index(drop=True)\n",
+ "df3"
+ ],
+ "execution_count": 7,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " numeros_telefone | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " (285) 608-2448 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " (765) 368-1506 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " (255) 826-9050 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " (596) 336-5508 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " (311) 799-3883 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " (410) 665-4447 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " (464) 788-2397 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " (511) 821-7870 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " (554) 994-1517 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " (650) 684-1437 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " (812) 816-0881 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " (821) 642-8987 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " (885) 407-1719 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " (935) 875-2054 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " (943) 769-1061 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " numeros_telefone\n",
+ "0 (285) 608-2448\n",
+ "1 (765) 368-1506\n",
+ "2 (255) 826-9050\n",
+ "3 (596) 336-5508\n",
+ "4 (311) 799-3883\n",
+ "5 (410) 665-4447\n",
+ "6 (464) 788-2397\n",
+ "7 (511) 821-7870\n",
+ "8 (554) 994-1517\n",
+ "9 (650) 684-1437\n",
+ "10 (812) 816-0881\n",
+ "11 (821) 642-8987\n",
+ "12 (885) 407-1719\n",
+ "13 (935) 875-2054\n",
+ "14 (943) 769-1061"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 7
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_06.ipynb b/Desafio_06.ipynb
index 4508023..d3d88df 100644
--- a/Desafio_06.ipynb
+++ b/Desafio_06.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -60,26 +60,136 @@
"metadata": {
"id": "mvxpy_vCf6Jh",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "1553ffc6-3a70-412a-fee6-2d4850b426aa"
},
"source": [
- "# Seu código"
+ "# Usando set\n",
+ "a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n",
+ "b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n",
+ "def inter(lista_a,lista_b):\n",
+ " inter = set(lista_a) & set(lista_b)\n",
+ " inter_final = list(inter)\n",
+ " return inter_final\n",
+ "inter(b,a)\n"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 2,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "[1, 2, 3, 5, 8, 13]"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 2
+ }
+ ]
},
{
"cell_type": "code",
"metadata": {
"id": "ly-N_Aq624RQ",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 235
+ },
+ "outputId": "d871c1b6-a4d6-477a-b016-06622836585b"
},
"source": [
- ""
+ "# Usando Data Frame\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "a_df = pd.DataFrame({'Coluna A':a}).drop_duplicates()\n",
+ "b_df = pd.DataFrame({'Coluna B':b}).drop_duplicates()\n",
+ "#print(a_df)\n",
+ "#print(b_df)\n",
+ "#c_df = pd.merge(a_df,b_df,how = 'inner',left_on = 'Coluna A', right_on= 'Coluna B',validate = '1:1')\n",
+ "#c_df\n",
+ "a_df_u = pd.DataFrame({'Única':a}).drop_duplicates()\n",
+ "b_df_u = pd.DataFrame({'Única':b}).drop_duplicates()\n",
+ "c_df = pd.merge(a_df_u,b_df_u,how = 'inner',on='Única',validate = '1:1')\n",
+ "c_df"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 4,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Única | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Única\n",
+ "0 1\n",
+ "1 2\n",
+ "2 3\n",
+ "3 5\n",
+ "4 8\n",
+ "5 13"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 4
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_07.ipynb b/Desafio_07.ipynb
index 5107d99..b0cebc1 100644
--- a/Desafio_07.ipynb
+++ b/Desafio_07.ipynb
@@ -5,7 +5,6 @@
"colab": {
"name": "Desafio 7.ipynb",
"provenance": [],
- "authorship_tag": "ABX9TyPinyzdF60Dyi+YfEQiCPfO",
"include_colab_link": true
},
"kernelspec": {
@@ -21,7 +20,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -58,7 +57,7 @@
" '(228) 976-9699', '(757) 450-9985', '(491) 666-5367',\n",
" ]"
],
- "execution_count": 0,
+ "execution_count": 4,
"outputs": []
},
{
@@ -89,7 +88,7 @@
" '(822) 640-8496', '(227) 389-3685', '(429) 264-7427', \n",
" '(397) 845-8267']"
],
- "execution_count": 0,
+ "execution_count": 5,
"outputs": []
},
{
@@ -107,13 +106,94 @@
"metadata": {
"id": "_OSrDQ1noh62",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 255
+ },
+ "outputId": "fe353633-fecf-4607-c237-098d9eeba5b1"
},
"source": [
- ""
+ "# Solução usando for e append\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "nao_entraram = []\n",
+ "for i in telefones_alunos:\n",
+ " if i in entraram_no_grupo:\n",
+ " pass\n",
+ " else:\n",
+ " nao_entraram = np.append(nao_entraram,i)\n",
+ " print (i)"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 7,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "(873) 810-8267\n",
+ "(300) 303-5462\n",
+ "(941) 225-3869\n",
+ "(294) 430-7720\n",
+ "(835) 955-1498\n",
+ "(897) 932-2512\n",
+ "(640) 427-2597\n",
+ "(856) 338-7094\n",
+ "(641) 367-5279\n",
+ "(964) 710-9625\n",
+ "(403) 343-7705\n",
+ "(797) 649-3653\n",
+ "(757) 450-9985\n",
+ "(491) 666-5367\n"
+ ],
+ "name": "stdout"
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "sIVz0zmdYYX4",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 255
+ },
+ "outputId": "3c94d2fd-6b1c-42dd-8a0a-8db336e902d7"
+ },
+ "source": [
+ "#Solução usando set\n",
+ "lista_nao_entraram = set(telefones_alunos) - set(entraram_no_grupo)\n",
+ "#type(set_alunos)\n",
+ "#lista_nao_entraram = list(set_alunos)\n",
+ "lista_nao_entraram"
+ ],
+ "execution_count": 9,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "{'(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'}"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 9
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_08.ipynb b/Desafio_08.ipynb
index c6fed05..9d2e426 100644
--- a/Desafio_08.ipynb
+++ b/Desafio_08.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -48,7 +48,10 @@
"\n",
"Escreva um script Python para encontrar as 10 palavras mais longas em um arquivo.\n",
"\n",
- "O arquivo TXT está localizado na mesma pasta do projeto (texto.txt)."
+ "O arquivo TXT está localizado na mesma pasta do projeto (texto.txt).\n",
+ "(texto.txt). texto.txt =\n",
+ "What is Python language?\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 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."
]
},
{
@@ -56,13 +59,205 @@
"metadata": {
"id": "EknxjSG0f6Jo",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 419
+ },
+ "outputId": "ade2e496-1e9e-4241-ae52-5a78dde37b00"
},
"source": [
- "# Seu código"
+ "#Solução com Data Frame\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "texto = '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.'\n",
+ "proibidos = ',.()'\n",
+ "for elemento in proibidos:\n",
+ " texto = texto.replace(elemento,' ')\n",
+ "novo_texto = texto.split()\n",
+ "func_vect_len = np.vectorize(len)\n",
+ "texto_tamanho = func_vect_len(novo_texto)\n",
+ "#print(texto_tamanho)\n",
+ "#df = pd.DataFrame({'palavras':novo_texto,'dimensao':texto_tamanho}).sort_values('dimensao',ascending=False)[0:10]\n",
+ "#df = pd.DataFrame({'palavras':novo_texto,'dimensao':texto_tamanho}).sort_values('dimensao',ascending=False).head(10)\n",
+ "#df = pd.DataFrame({'palavras':novo_texto,'dimensao':texto_tamanho}).sort_values('dimensao',ascending=False).tail(10)\n",
+ "df = pd.DataFrame({'palavras':novo_texto,'dimensao':texto_tamanho}).sort_values('dimensao',ascending=False)\n",
+ "#df.info() # ter uma ideia de quantidade de colunas, dados faltantes, espaço memória\n",
+ "#df.describe() # nos dá uma ideia estatística da amostra\n",
+ "df\n"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " palavras | \n",
+ " dimensao | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 45 | \n",
+ " object-oriented | \n",
+ " 15 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " general-purpose | \n",
+ " 15 | \n",
+ "
\n",
+ " \n",
+ " | 68 | \n",
+ " comprehensive | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " | 92 | \n",
+ " intermediate | \n",
+ " 12 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " programming | \n",
+ " 11 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 53 | \n",
+ " It | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 74 | \n",
+ " we | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 65 | \n",
+ " a | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 55 | \n",
+ " a | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " a | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
98 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " palavras dimensao\n",
+ "45 object-oriented 15\n",
+ "6 general-purpose 15\n",
+ "68 comprehensive 13\n",
+ "92 intermediate 12\n",
+ "49 programming 11\n",
+ ".. ... ...\n",
+ "53 It 2\n",
+ "74 we 2\n",
+ "65 a 1\n",
+ "55 a 1\n",
+ "2 a 1\n",
+ "\n",
+ "[98 rows x 2 columns]"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 3
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "sjpXsL14ejBh",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 374
+ },
+ "outputId": "07a158fc-e21a-40a9-84d1-70455ea84b0a"
+ },
+ "source": [
+ "# Solução usando !wget, open e sorted\n",
+ "!wget https://raw.githubusercontent.com/awarischool/br-python-challenges/master/texto.txt\n",
+ "with open('texto.txt', 'r') as txt:\n",
+ " texto = txt.read().replace('.',' ').replace('?',' ').replace(',',' ').split()\n",
+ "lista_ordenada = sorted(texto,key=len,reverse=True)[:10]\n",
+ "lista_ordenada"
+ ],
+ "execution_count": 4,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "--2020-08-17 17:33:19-- https://raw.githubusercontent.com/awarischool/br-python-challenges/master/texto.txt\n",
+ "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...\n",
+ "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.\n",
+ "HTTP request sent, awaiting response... 200 OK\n",
+ "Length: 766 [text/plain]\n",
+ "Saving to: ‘texto.txt’\n",
+ "\n",
+ "\rtexto.txt 0%[ ] 0 --.-KB/s \rtexto.txt 100%[===================>] 766 --.-KB/s in 0s \n",
+ "\n",
+ "2020-08-17 17:33:20 (35.9 MB/s) - ‘texto.txt’ saved [766/766]\n",
+ "\n"
+ ],
+ "name": "stdout"
+ },
+ {
+ "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']"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 4
+ }
+ ]
},
{
"cell_type": "code",
@@ -74,8 +269,8 @@
"source": [
""
],
- "execution_count": 0,
+ "execution_count": null,
"outputs": []
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_09.ipynb b/Desafio_09.ipynb
index 1426b31..8b596f0 100644
--- a/Desafio_09.ipynb
+++ b/Desafio_09.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -57,23 +57,128 @@
"colab": {}
},
"source": [
- "# Seu código"
+ "# Usando append\n",
+ "def multiplos(limite):\n",
+ " lista = []\n",
+ " for i in range(limite):\n",
+ " x = i*3\n",
+ " y = i*5\n",
+ " lista.append(x)\n",
+ " lista.append(y)\n",
+ " lista_limitada = sorted(i for i in lista if i <=limite)\n",
+ " lista_soma = sum(lista_limitada)\n",
+ " return lista_soma\n",
+ " #multiplos(20)\n",
+ " \n"
],
- "execution_count": 0,
+ "execution_count": 14,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
- "id": "a_6aqcKp6wrN",
+ "id": "6TO0TNmyisvE",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "5b491865-822a-4dc9-92a4-71770db985c2"
},
"source": [
- ""
+ "multiplos(20)"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 16,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "93"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 16
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "KVf_Pa0qh21E",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 51
+ },
+ "outputId": "3f6d9b7f-596b-45e6-c40b-8923022d4c0a"
+ },
+ "source": [
+ "# Usando arange\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "a= int(input('Digite um número para encontrarmos os múltiplos de 3 ou 5: '))\n",
+ "def soma_mult_3_5(numero):\n",
+ " arr = np.arange(1,numero+1) # arr é um array que vai de 1 até o número a que iremos inputar; 1,2,3,4,5,6... a\n",
+ " resultado = arr[(arr%3 == 0) | (arr%5 == 0)] # filtrando o array com as condições de divisão por 3 e 5 serão armazenados no array resultado\n",
+ " soma_resultado = np.sum(resultado)\n",
+ " return soma_resultado\n",
+ "soma_mult_3_5(a)"
+ ],
+ "execution_count": 12,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "Digite um número para encontrarmos os múltiplos de 3 ou 5: 20\n"
+ ],
+ "name": "stdout"
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "98"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 12
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "9Ge1_lWwiZ7-",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "becc8c9e-fae7-4f5c-b350-0994b41e8990"
+ },
+ "source": [
+ "3+ 5+ 6+ 9+ 10+ 12+ 15+ 18+20"
+ ],
+ "execution_count": 13,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "98"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 13
+ }
+ ]
}
]
-}
+}
\ No newline at end of file
diff --git a/Desafio_10.ipynb b/Desafio_10.ipynb
index 0ed40b5..3f3179a 100644
--- a/Desafio_10.ipynb
+++ b/Desafio_10.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -64,12 +64,61 @@
"metadata": {
"id": "IJ70pUjnf6Jw",
"colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "cedac1ff-f04f-4d7c-b795-187aedd53e0d"
+ },
+ "source": [
+ "# Usando len e reverse\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]\n",
+ "#sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89,100,101,102]\n",
+ "quant = len(sampleList)\n",
+ "if (quant%3 ==0):\n",
+ " tamanho_particao = int(quant/3)\n",
+ " lista_um=sampleList[0:tamanho_particao]\n",
+ " lista_dois=sampleList[tamanho_particao:tamanho_particao*2]\n",
+ " lista_tres=sampleList[tamanho_particao*2:]\n",
+ " lista_um.reverse()\n",
+ " lista_dois.reverse()\n",
+ " lista_tres.reverse()\n",
+ " #inverter + else\n",
+ " print((lista_um),(lista_dois),(lista_tres))\n",
+ "else:\n",
+ " print('A lista não é múltipla de 3')"
+ ],
+ "execution_count": 2,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "[8, 45, 11] [12, 14, 23] [89, 45, 78]\n"
+ ],
+ "name": "stdout"
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "4A1XiSy3lXTH",
+ "colab_type": "code",
"colab": {}
},
"source": [
- "# Seu código"
+ "# usando len\n",
+ "def quebra_inverte(lista):\n",
+ " terco_1 = int(len(lista)/3)\n",
+ " terco_2 = terco_1*2\n",
+ " parada_1 = lista[0:terco_1]\n",
+ " parada_2 = lista[terco_1:terco_2]\n",
+ " parada_3 = lista[terco_2:]\n",
+ " return parada_1[::-1],parada_2[::-1],parada_3[::-1],"
],
- "execution_count": 0,
+ "execution_count": 5,
"outputs": []
},
{
@@ -77,13 +126,30 @@
"metadata": {
"id": "pNrXNVqf8Wc1",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "f91f91c5-62a4-437c-f3e5-260ccc6c4490"
},
"source": [
- ""
+ "quebra_inverte(sampleList)"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 4,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "([8, 45, 11], [12, 14, 23], [89, 45, 78])"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 4
+ }
+ ]
}
]
}
\ No newline at end of file
diff --git a/Desafio_11.ipynb b/Desafio_11.ipynb
index aa23e34..79165ab 100644
--- a/Desafio_11.ipynb
+++ b/Desafio_11.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -60,11 +60,18 @@
"colab": {}
},
"source": [
- "# Seu código\n",
- "def contar_pares_impares(entrada):\n",
- " pass"
+ "# Usando tupla\n",
+ "def par_e_impar(lista_numeros):\n",
+ " pares = 0\n",
+ " impares = 0\n",
+ " for num in lista_numeros:\n",
+ " if num % 2 == 0:\n",
+ " pares = pares+1\n",
+ " else:\n",
+ " impares= impares+1\n",
+ " return tuple((pares,impares))"
],
- "execution_count": 0,
+ "execution_count": 1,
"outputs": []
},
{
@@ -72,77 +79,71 @@
"metadata": {
"id": "OQG6erslSjri",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "50d84ca4-1c83-42eb-d6f7-39533231ac6a"
},
"source": [
- ""
+ "sequencia = [6, 2, 7, -5, 8, -4]\n",
+ "par_e_impar(sequencia)"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "(4, 2)"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 3
+ }
+ ]
},
{
"cell_type": "code",
"metadata": {
"id": "BSuBza0GSjyM",
"colab_type": "code",
- "colab": {}
- },
- "source": [
- ""
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "cell_type": "code",
- "metadata": {
- "id": "y_iM2tgF35t7",
- "colab_type": "code",
- "colab": {}
- },
- "source": [
- "# Não modifique o código abaixo! Vamos testar algumas entradas\n",
- "msg_erro = \"Saída da função para a entrada {} deveria ser {}\"\n",
- "\n",
- "entrada = [6, 2, 7, -5, 8, -4]\n",
- "saida_esperada = (4, 2)\n",
- "assert contar_pares_impares(entrada)==saida_esperada, msg_erro.format(entrada, saida_esperada)\n",
- "\n",
- "entrada = [-3, 2, 7, -5, 8, -4]\n",
- "saida_esperada = (3, 3)\n",
- "assert contar_pares_impares(entrada)==saida_esperada, msg_erro.format(entrada, saida_esperada)\n",
- "\n",
- "\n",
- "# Se nenhuma mensagem for impressa abaixo, significa que a função está implementada corretamente"
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "cell_type": "code",
- "metadata": {
- "id": "Nfb7lBpq35_6",
- "colab_type": "code",
- "colab": {}
- },
- "source": [
- ""
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "cell_type": "code",
- "metadata": {
- "id": "UwT4tLtzR3_U",
- "colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 34
+ },
+ "outputId": "a73e401d-7469-4c6d-fd61-4d480ddf0c54"
},
"source": [
- ""
+ "# Usando base de dados grande via random\n",
+ "#par_impar = [6, 2, 7, -5, 8, -4]\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "par_impar = np.random.randint(0,4000,1000)\n",
+ "count_par = 0\n",
+ "count_impar = 0\n",
+ "for i in par_impar:\n",
+ " if i % 2 == 0:\n",
+ " count_par = count_par +1\n",
+ " #print('par')\n",
+ " else:\n",
+ " count_impar = count_impar + 1\n",
+ " #print('impar')\n",
+ "resultado = (count_par, count_impar)\n",
+ "print(resultado)"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 5,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "(518, 482)\n"
+ ],
+ "name": "stdout"
+ }
+ ]
}
]
}
\ No newline at end of file
diff --git a/Desafio_12.ipynb b/Desafio_12.ipynb
index 0ebd52a..0115d8b 100644
--- a/Desafio_12.ipynb
+++ b/Desafio_12.ipynb
@@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
- "
"
+ "
"
]
},
{
@@ -71,12 +71,107 @@
"metadata": {
"id": "UGgtGYGGf6J3",
"colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 306
+ },
+ "outputId": "804544a7-838d-468a-895c-30312025a70d"
+ },
+ "source": [
+ "# Usando caracter do numpy\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "#senha_input = input('Digite uma senha que contenha entre 6 e 16 caracteres, 1 letra minúscula, 1 maiúscula, 1 número e 1 caracter especial: ')\n",
+ "senha_input = [\"12345678\", \"J3sus0\", \"#Te5t300\", \"J*90j12374\", \"Michheeul\", \"Monk3y6\",\"Qw#1234\"]\n",
+ "#for caracter in senha:\n",
+ " #print(caracter.isdigit())\n",
+ "#any(caracter.isdigit() for caracter in senha) # any:retorna verdadeiro se qquer valor da condição for verdadeiro\n",
+ "#not any(caracter.isdigit() for caracter in senha) # not any: retorna falso se qquer valor da condição for verdadeiro\n",
+ "def senha_valida(senha):\n",
+ " caracteres_especiais = ['$','#','@']\n",
+ " variavel_dummy = True\n",
+ "\n",
+ " if len(senha) < 6:\n",
+ " variavel_dummy = False\n",
+ " print('Senha inválida por ter menos que 6 digitos')\n",
+ " if len(senha) > 16:\n",
+ " variavel_dummy = False\n",
+ " print('Senha inválida por ter mais que 16 digitos')\n",
+ " if not any(caracter.isdigit() for caracter in senha):\n",
+ " variavel_dummy = False\n",
+ " print('Senha inválida por não possuir nenhum número')\n",
+ " if not any(caracter.islower() for caracter in senha):\n",
+ " variavel_dummy = False\n",
+ " print('Senha inválida por não possuir nenhuma letra minúscula')\n",
+ " if not any(caracter.isupper() for caracter in senha):\n",
+ " variavel_dummy = False\n",
+ " print('Senha inválida por não possuir nenhuma letra maiúscula')\n",
+ " if not any(caracter in caracteres_especiais for caracter in senha):\n",
+ " variavel_dummy = False\n",
+ " print('Senha inválida por não possuir um dos seguintes caracteres especiais: $,#,@')\n",
+ " if variavel_dummy == True:\n",
+ " print('Senha Válida')\n",
+ " \n",
+ "#senha_valida(senha in senha_input for senha in [6])\n",
+ "for r in senha_input:\n",
+ " print(r)\n",
+ " senha_valida(senha = r)"
+ ],
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "text": [
+ "12345678\n",
+ "Senha inválida por não possuir nenhuma letra minúscula\n",
+ "Senha inválida por não possuir nenhuma letra maiúscula\n",
+ "Senha inválida por não possuir um dos seguintes caracteres especiais: $,#,@\n",
+ "J3sus0\n",
+ "Senha inválida por não possuir um dos seguintes caracteres especiais: $,#,@\n",
+ "#Te5t300\n",
+ "Senha Válida\n",
+ "J*90j12374\n",
+ "Senha inválida por não possuir um dos seguintes caracteres especiais: $,#,@\n",
+ "Michheeul\n",
+ "Senha inválida por não possuir nenhum número\n",
+ "Senha inválida por não possuir um dos seguintes caracteres especiais: $,#,@\n",
+ "Monk3y6\n",
+ "Senha inválida por não possuir um dos seguintes caracteres especiais: $,#,@\n",
+ "Qw#1234\n",
+ "Senha Válida\n"
+ ],
+ "name": "stdout"
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "KrL-w8eDp19c",
+ "colab_type": "code",
"colab": {}
},
"source": [
- "# Seu código"
+ "# Usando string\n",
+ "import string\n",
+ "def verifica_senha(senha):\n",
+ " import string\n",
+ " especiais = [\"$\",\"#\",\"@\"]\n",
+ " minusculas = list(string.ascii_lowercase)\n",
+ " maiusculas = list(string.ascii_uppercase)\n",
+ " range_list = [str(i) for i in range(10)]\n",
+ " if len(senha) < 6 or len(senha) > 16:\n",
+ " return \"Senha Inválida\"\n",
+ " elif len(set(senha) & set(minusculas)) == 0:\n",
+ " return \"Senha inválida\"\n",
+ " elif len(set(senha) & set(maiusculas)) == 0:\n",
+ " return \"Senha inválida\"\n",
+ " elif len(set(senha) & set(range_list)) == 0:\n",
+ " return \"Senha inválida\"\n",
+ " else: \n",
+ " return\"Senha válida\""
],
- "execution_count": 0,
+ "execution_count": 5,
"outputs": []
},
{
@@ -84,13 +179,66 @@
"metadata": {
"id": "n8F01NzD9uHm",
"colab_type": "code",
- "colab": {}
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 35
+ },
+ "outputId": "7bd0df76-c7cf-4b7e-cf73-318aa646e613"
},
"source": [
- ""
+ "verifica_senha('sE1#tgh')"
],
- "execution_count": 0,
- "outputs": []
+ "execution_count": 6,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "string"
+ },
+ "text/plain": [
+ "'Senha válida'"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 6
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "mzPDaQIuqcz5",
+ "colab_type": "code",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 35
+ },
+ "outputId": "9e2c40a9-c55a-48e5-ed30-0e06ee124cb8"
+ },
+ "source": [
+ "verifica_senha('1234')"
+ ],
+ "execution_count": 8,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "string"
+ },
+ "text/plain": [
+ "'Senha Inválida'"
+ ]
+ },
+ "metadata": {
+ "tags": []
+ },
+ "execution_count": 8
+ }
+ ]
}
]
}
\ No newline at end of file