From 25037740e297aa1947a119bfeba34ae706d6c713 Mon Sep 17 00:00:00 2001 From: Alceu Rosa Neto Date: Thu, 16 Apr 2020 14:55:14 -0300 Subject: [PATCH] ajuste com comentarios de aula --- .vscode/launch.json | 15 ++ .vscode/settings.json | 15 ++ Roteiro da Aula.txt | 221 ++++++++++++++++++ executa_modulo.py | 3 + pacote/__init__.py | 0 pacote/modulo.py | 16 ++ testes/{atores_testes.py => testes_atores.py} | 0 testes/{fase_testes.py => testes_fase.py} | 0 .../{integracao.py => testes_integracao.py} | 0 testes/testes_soma.py | 9 + 10 files changed, 279 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 Roteiro da Aula.txt create mode 100644 executa_modulo.py create mode 100644 pacote/__init__.py create mode 100644 pacote/modulo.py rename testes/{atores_testes.py => testes_atores.py} (100%) rename testes/{fase_testes.py => testes_fase.py} (100%) rename testes/{integracao.py => testes_integracao.py} (100%) create mode 100644 testes/testes_soma.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..d2cefb74a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Arquivo Atual", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..ef7e900d7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "python.testing.pytestArgs": [ + "testes" + ], + "python.testing.unittestEnabled": true, + "python.testing.nosetestsEnabled": false, + "python.testing.pytestEnabled": false, + "python.testing.unittestArgs": [ + "-v", + "-s", + "./testes", + "-p", + "*test*.py" + ] +} \ No newline at end of file diff --git a/Roteiro da Aula.txt b/Roteiro da Aula.txt new file mode 100644 index 000000000..f83c5b595 --- /dev/null +++ b/Roteiro da Aula.txt @@ -0,0 +1,221 @@ +ideias +******************************************************************************* + 1 DIA +******************************************************************************* +Afiando o Machado +Instalação Python 3.8 +VSCODE +GIT +python -V + +import this + +Fundamentos procedurais: +int +operações +, -, *, /, //(retorna inteiro da divisão), %(modulo), ** (potenciação) +float +Variaveis +type() +NOT, OR, AND +If XXX : + +******************************************************************************* + 2 DIA +******************************************************************************* + +String, ', ", ''', """ +print() +dir() +.lower +.upper +help("".lower) +.len("") +__gt__ - Dunder - “Double Under (Underscores)” +2 + "2" => error TypeError - fortemente tipado (exceto int para float) +2+2=4 +"2"+"2" = 22 Concatenação +cast - str(), int(), float() +str(2qwe) = erro (não faz sentido) + +Container (string acessada como vetor) +"qweasd"[1] = "w" (começa a contagem do zero) +"qweasd"[-1] = "d" (negativo conta do fim p o começo) +"qweasd"[2:4] = "ea" (intervalo fechado a esquerda do : e intervalo aberto depois: ) +"qweasd"[0:4:2] = "qe" (Pula o passo de seleção depois do segundo : ) +"qweasd"[::2] = "qes" (Todos os caracteres pares da string ) +"qweasd"[1::2] = "wad" (Todos os caracteres impares da string ) +"qweasd"[::] = "qweasd" (Todos os caracteres pares da string ) +"qweasd"[::-1] = "dsaewq" (inverte string ) +'qwe'*3 => 'qweqweqwe' + +Definição de listas +lista=[] +type(lista) +len(lista) +dir(lista) +lista.append(1) +lista.reverse() +numeros = list(range(10)) =>[0,1,2,3,4,5,6,7,8,9] +numeros[0]=>0 +numeros[-1]=>9 +numeros[:5]=>[0,1,2,3,4] +numeros[::-2]=>[9,7,5,3,1] +numeros + [10,11,12]=>[0,1,2,3,4,5,6,7,8,9],10,11,12 + +list(range(1,10)) =>[1,2,3,4,5,6,7,8,9] +list(range(1,10,2)) =>[1,,3,,5,,7,,9] + +tupla = (1,2,3) lista imutavel +tupla = 1,2,3 +p,s,t = tupla (desempacotamento) +p=>1 +s=>2 +t=>3 +p,s,t,q = tupla => erro +p,demais = tupla +p=>1 +demais = [2,3] + +L1, L2, L3, *_ = "qweasd" +L1="q" +L2= "w" +L3= "e" + +for letra in "qweasd": + print(letra) + +dicionario = {'br':'Brasil','fr':'França'} +dicionario['br'] = 'Brasil' +dicionario.get('br') = 'Brasil' + +dicionario['en']='Ingles' +len(dicionario) =>3 + +for lingua in dicionario: + print(lingua) +br +fr (Lista as chaves) +en + +for chave in dicionario: print(chave, dicionario[chave],sep='->') +br -> Brasil +fr -> França +en -> Ingles + +for chave in dicionario.keys(): print(chave, dicionario[chave],sep='->') +br -> Brasil +fr -> França +en -> Ingles + +for itens in dicionario.itens(): print(itens) +(br,Brasil) +(fr,França) +(en,Ingles) + +for pais, lingua in dicionario.itens(): print(pais, lingua ,sep='->') +br -> Brasil +fr -> França +en -> Ingles + +Funções +para criar uma função mas nao tem nada dentro dela +def sem_retorno(): + pass + +sem passagem de parametros e sem retorno de parametros +def imprimir(): + print("Inicio") + print("final") + +type(imprimir) => function + +passando parametros e sem retorno de parametros +def soma(a,b): + print(a+b) + +passando parametros e retornando parametros +def soma(a,b): + return a+b + +nao sei qnts elementos eu vou passar p função +def soma(*numeros): + type(numeros)=> tupla + +soma(1,2,3,4) + +def soma(*numeros): + total=0 + for numero in numeros: + total = total + numero + return total + +t1=(1,2) +t2=(1,2) +t1==t2 => True + +id(t1) == id(t2) =>False +t1 is t2 =>False + +modulo (é um arquivo .py com scripts python) +pacote (é um diretorio com um modulo especial __init__.py ) +************************************************************ +criando um modulo pythonico: +dir pacote +file modulo.py + +def soma(*args): + total=0 + for n in args: + total += n + return total + +print (__name__) + + +Usar esta estrutura para controlar qnd é roda o file no +modulo ou chamado em outra função . Legal p demonstrar +codigo TESTES na AULA + +if __name__ == '__main__': + print(soma()) + print(soma(1)) + print(soma(1,2)) + print(soma(1,2,3)) + print(soma(1,2,3,4)) + +************************************************************** +Executando... +python .\pacote\modulo.py +python -m pacote.modulo + +************************************************************** +debug e git (ENSINE SEMPRE NA PRIMEIRA AULA DEBUG é VIDA) + +************************************************************** +importando o modulo: + + + +from pacote.modulo import soma as s + +print(s(7,8)) + + +******************************************************************************* + 3 DIA - ORIENTACAO A OBJETOS +******************************************************************************* +Teste automatico de SW - Construir programas p testar outros programas +unitest - padrao python +pytest - bom + +exemplo do teste para o modulo + +Uma classe é uma forma de gelo. + + + + + + + + diff --git a/executa_modulo.py b/executa_modulo.py new file mode 100644 index 000000000..63cd9e28f --- /dev/null +++ b/executa_modulo.py @@ -0,0 +1,3 @@ +from pacote.modulo import soma as s + +print(s(7,8)) diff --git a/pacote/__init__.py b/pacote/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pacote/modulo.py b/pacote/modulo.py new file mode 100644 index 000000000..8ddce1e36 --- /dev/null +++ b/pacote/modulo.py @@ -0,0 +1,16 @@ + + +def soma(*args): + total=0 + for n in args: + total += n + return total + +print (__name__) + +if __name__ == '__main__': + print(soma()) + print(soma(1)) + print(soma(1,2)) + print(soma(1,2,3)) + print(soma(1,2,3,4)) diff --git a/testes/atores_testes.py b/testes/testes_atores.py similarity index 100% rename from testes/atores_testes.py rename to testes/testes_atores.py diff --git a/testes/fase_testes.py b/testes/testes_fase.py similarity index 100% rename from testes/fase_testes.py rename to testes/testes_fase.py diff --git a/testes/integracao.py b/testes/testes_integracao.py similarity index 100% rename from testes/integracao.py rename to testes/testes_integracao.py diff --git a/testes/testes_soma.py b/testes/testes_soma.py new file mode 100644 index 000000000..42916ca97 --- /dev/null +++ b/testes/testes_soma.py @@ -0,0 +1,9 @@ +from unittest import TestCase +from pacote.modulo import soma as s + + +class TestSoma(TestCase): + def test_soma(self): + res = s(1,3) + self.assertEqual(4,res) + \ No newline at end of file