-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f5a4f9
commit 4e48f37
Showing
1 changed file
with
374 additions
and
0 deletions.
There are no files selected for viewing
374 changes: 374 additions & 0 deletions
374
Abril/Desafios Propostos AED FACULDADE/aula7(iteração).ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,374 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Iteração\n", | ||
"\n", | ||
"for, while e enumarate" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### FOR" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Estamos no elemento 1\n", | ||
"Estamos no elemento 2\n", | ||
"Estamos no elemento 3\n", | ||
"Estamos no elemento 4\n", | ||
"Estamos no elemento 5\n", | ||
"Estamos no elemento 6\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for elemento in [1,2,3,4,5,6]:\n", | ||
" print(\"Estamos no elemento \", elemento)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Estamos no elemento S\n", | ||
"Estamos no elemento T\n", | ||
"Estamos no elemento R\n", | ||
"Estamos no elemento I\n", | ||
"Estamos no elemento N\n", | ||
"Estamos no elemento G\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for elemento in \"STRING\":\n", | ||
" print(\"Estamos no elemento \", elemento)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"estamos no elemento 0\n", | ||
"estamos no elemento 1\n", | ||
"estamos no elemento 2\n", | ||
"estamos no elemento 3\n", | ||
"estamos no elemento 4\n", | ||
"estamos no elemento 5\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for elemento in range(len(\"STRING\")):\n", | ||
" print(\"estamos no elemento \", elemento)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### WHILE" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Estamos no elemento 0\n", | ||
"Estamos no elemento 1\n", | ||
"Estamos no elemento 2\n", | ||
"Estamos no elemento 3\n", | ||
"Estamos no elemento 4\n", | ||
"Estamos no elemento 5\n", | ||
"Estamos no elemento 6\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"elemento = 0\n", | ||
"\n", | ||
"while elemento <= len([1,2,3,4,5,6]):\n", | ||
" print(\"Estamos no elemento \", elemento) \n", | ||
" elemento += 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Estamos no elemento S\n", | ||
"Estamos no elemento T\n", | ||
"Estamos no elemento R\n", | ||
"Estamos no elemento I\n", | ||
"Estamos no elemento N\n", | ||
"Estamos no elemento G\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"s = \"STRING\"\n", | ||
"indice = 0\n", | ||
"\n", | ||
"while indice in range(len(s)):\n", | ||
" print(\"Estamos no elemento \", s[indice])\n", | ||
" indice += 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### ENUMARATE" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0 t\n", | ||
"1 r\n", | ||
"2 a\n", | ||
"3 n\n", | ||
"4 q\n", | ||
"5 u\n", | ||
"6 i\n", | ||
"7 l\n", | ||
"8 o\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"palavra = \"tranquilo\"\n", | ||
"\n", | ||
"#INDICE(INT) E LETRA(CHAR)\n", | ||
"for indice, letra in enumerate(palavra):\n", | ||
" print(indice, letra)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 43, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"<enumerate object at 0x000001820FB00360> <enumerate object at 0x000001820FE0A8E0>\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"lista = [\"eat\", \"sleep\", \"repeat\"]\n", | ||
"palavra = \"geek\"\n", | ||
"\n", | ||
"objeto1 = enumerate(lista)\n", | ||
"objeto2 = enumerate(palavra)\n", | ||
"\n", | ||
"print(objeto1, objeto2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 45, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Tipo: <class 'enumerate'>\n", | ||
"[(0, 'eat'), (1, 'sleep'), (2, 'repeat')]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(\"Tipo: \", type(objeto1))\n", | ||
"print(list(enumerate(lista)))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 47, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[(2, 'g'), (3, 'e'), (4, 'e'), (5, 'k')]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(list(enumerate(palavra,2)))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 48, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"s = \"viva o python\"\n", | ||
"\n", | ||
"for ch in s:\n", | ||
" print(\"Oi\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 49, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n", | ||
"Oi\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"s = \"viva o python\"\n", | ||
"\n", | ||
"for ch in s[3:8]:\n", | ||
" print(\"Oi\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Exercício" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 51, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"A quantidade de números pares foram 8\n", | ||
"A quantidade de números impar foram 2\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"numerosPares = 0\n", | ||
"numerosImpar = 0\n", | ||
"\n", | ||
"for i in range(10):\n", | ||
" numero = int(input(\"Digite um númwro inteiro: \"))\n", | ||
"\n", | ||
" if numero % 2 == 0:\n", | ||
" numerosPares += 1\n", | ||
" else:\n", | ||
" numerosImpar +=1\n", | ||
"\n", | ||
"\n", | ||
"print(\"A quantidade de números pares foram \", numerosPares)\n", | ||
"print(\"A quantidade de números impar foram \", numerosImpar)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"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.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |