Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Desafio 10 de Python - Awari_Data Sciece - Aluno: Marcilio Duarte_Turma_DS38",
"provenance": [],
"authorship_tag": "ABX9TyM0o5DAV9vjIdntuusS8UH1",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/marcilioduarte/br-python-challenges/blob/master/Desafio_10_de_Python_Awari_Data_Sciece_Aluno_Marcilio_Duarte_Turma_DS38.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"![](https://i.imgur.com/YX6UATs.png)"
],
"metadata": {
"id": "mZ7eDfdeJpXc"
}
},
{
"cell_type": "markdown",
"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] "
],
"metadata": {
"id": "U5fw_LumJpEU"
}
},
{
"cell_type": "code",
"source": [
"sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]"
],
"metadata": {
"id": "hccSagwTJx-9"
},
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#Solução 1:\n",
"\n",
"n = 3\n",
"def Parte_1(lst, n): \n",
" for i in range(0, len(sampleList), n): \n",
" return list(reversed(lst[i:i + n]))\n",
"def Parte_2(lst, n):\n",
" for i in range(3,3+n,n):\n",
" return list(reversed(lst[i:i+n]))\n",
"def Parte_3(lst, n):\n",
" for i in range(6,6+n,n):\n",
" return list(reversed(lst[i:i+n]))\n",
"\n",
"print(f'Parte 1: {(Parte_1(sampleList, n))}'\n",
" f'\\nParte 2: {(Parte_2(sampleList, n))}'\n",
" f'\\nParte 3: {(Parte_3(sampleList, n))}')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mTTuOT57aG3d",
"outputId": "9b336f30-547c-4ec6-e17c-bb8a692e2858"
},
"execution_count": 31,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Parte 1: [8, 45, 11]\n",
"Parte 2: [12, 14, 23]\n",
"Parte 3: [89, 45, 78]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Solução 2: resposta da awari\n",
"l1 = []\n",
"l2 = []\n",
"l3 = []\n",
"qtde = len(sampleList) / 3\n",
"if qtde.is_integer():\n",
" for elem in sampleList:\n",
" if len(l1) < qtde:\n",
" l1.append(elem)\n",
" parte_1 = reversed(l1)\n",
" elif len(l2) < qtde:\n",
" l2.append(elem)\n",
" parte_2 = reversed(l2)\n",
" else:\n",
" if len(l3) < qtde:\n",
" l3.append(elem)\n",
" parte_3 = reversed(l3)\n",
" print(f'Parte 1: {list(parte_1)}'\n",
" f'\\nParte 2: {list(parte_2)}'\n",
" f'\\nParte 3: {list(parte_3)}')\n",
"else:\n",
" print('A respectiva lista não pode ser dividida em 3 partes iguais!')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VCbwsZ2VehKA",
"outputId": "007f8353-6b1f-40c8-c578-f734941ab880"
},
"execution_count": 25,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Parte 1: [8, 45, 11]\n",
"Parte 2: [12, 14, 23]\n",
"Parte 3: [89, 45, 78]\n"
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Desafio 11 de Python - Awari_Data Sciece - Aluno: Marcilio Duarte_Turma_DS38",
"provenance": [],
"authorship_tag": "ABX9TyP/y9wswfpfNMfkO89d/P9c",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/marcilioduarte/br-python-challenges/blob/master/Desafio_11_de_Python_Awari_Data_Sciece_Aluno_Marcilio_Duarte_Turma_DS38.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"![](https://i.imgur.com/YX6UATs.png)"
],
"metadata": {
"id": "Khf4Hipaom-h"
}
},
{
"cell_type": "markdown",
"source": [
"### Desafio 11\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)`."
],
"metadata": {
"id": "_NGs9dWWodso"
}
},
{
"cell_type": "code",
"source": [
"#solução 1:\n",
"lista_aleatoria=[22,24,26,27,29,31,33]\n",
"pares=[]\n",
"impares=[]\n",
"def imp_ou_par(lst):\n",
" for i in lst:\n",
" if i%2==0:\n",
" pares.append(i)\n",
" elif i%2!=0:\n",
" impares.append(i)\n",
" tupla=(len(pares),len(impares))\n",
" print(f'A quantidade de números pares é: {len(pares)}', f'e a quantidade de números ímpares é: {len(impares)}')\n",
" print(f'Logo, a tupla é: {tupla}')\n",
"imp_ou_par(lista_aleatoria)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "D5A-HqQIopuF",
"outputId": "e772a098-e827-48b3-8580-d7f48bac9007"
},
"execution_count": 49,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"A quantidade de números pares é: 3 e a quantidade de números ímpares é: 4\n",
"Logo, a tupla é: (3, 4)\n"
]
}
]
}
]
}
Loading