-
Notifications
You must be signed in to change notification settings - Fork 9
feat: adiciona atividades modulo 1 e modulo 2 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
letxiz
wants to merge
2
commits into
Hygo:main
Choose a base branch
from
letxiz:leticia_branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
| [ | ||
| { | ||
| "id": 1, | ||
| "nome": "Leticia", | ||
| "email": "leticia@email.com", | ||
| "idade": 20, | ||
| "notas": [ | ||
| 8.0, | ||
| 9.0 | ||
| ], | ||
| "ativo": true | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "nome": "Rafael", | ||
| "email": "rafael@email.com", | ||
| "idade": 21, | ||
| "notas": [ | ||
| 7.0, | ||
| 6.0 | ||
| ], | ||
| "ativo": true | ||
| }, | ||
| { | ||
| "id": 3, | ||
| "nome": "Maria", | ||
| "email": "maria@email.com", | ||
| "idade": 19, | ||
| "notas": [ | ||
| 10.0, | ||
| 9.5 | ||
| ], | ||
| "ativo": true | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "nome": "Lucas", | ||
| "email": "lucas@email.com", | ||
| "idade": 22, | ||
| "notas": [ | ||
| 5.0, | ||
| 6.5 | ||
| ], | ||
| "ativo": true | ||
| } | ||
| ] |
This file contains hidden or 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,185 @@ | ||
| # Exercício 40 – Desafio Final: Sistema de Cadastro Completo | ||
| #Aluna: Leticia Alves | ||
|
|
||
| import json | ||
|
|
||
| ARQUIVO = "alunos.json" | ||
|
|
||
|
|
||
| def carregar() -> list[dict]: | ||
| """Carrega os alunos do arquivo JSON. | ||
|
|
||
| Returns: | ||
| list[dict]: Uma lista contendo os dicionários dos alunos. | ||
| Retorna uma lista vazia se o arquivo não existir. | ||
|
|
||
| Raises: | ||
| ValueError: Se o arquivo JSON existir, mas estiver inválido. | ||
| """ | ||
| try: | ||
| with open(ARQUIVO, "r") as f: | ||
| return json.load(f) | ||
| except FileNotFoundError: | ||
| return [] | ||
| except json.JSONDecodeError as exc: | ||
| raise ValueError(f"Arquivo JSON inválido: {ARQUIVO}") from exc | ||
|
|
||
|
|
||
| def salvar(alunos: list[dict]) -> None: | ||
| """Salva a lista de alunos no arquivo JSON. | ||
|
|
||
| Args: | ||
| alunos (list[dict]): A lista de dicionários dos alunos a ser salva. | ||
| """ | ||
| with open(ARQUIVO, "w") as f: | ||
| json.dump(alunos, f, indent=4) | ||
|
|
||
|
|
||
| def cadastrar_aluno( | ||
| nome: str, email: str, idade: int, notas: list[float] | ||
| ) -> dict: | ||
| """Cadastra um novo aluno no sistema e persiste no arquivo JSON. | ||
|
|
||
| Args: | ||
| nome (str): Nome completo do aluno. | ||
| email (str): Endereço de e-mail do aluno. | ||
| idade (int): Idade do aluno. | ||
| notas (list[float]): Lista com as notas do aluno. | ||
|
|
||
| Returns: | ||
| dict: O dicionário do aluno recém-criado com ID e status ativo. | ||
| """ | ||
| alunos = carregar() | ||
|
|
||
| aluno = { | ||
| "id": len(alunos) + 1, | ||
| "nome": nome, | ||
| "email": email, | ||
| "idade": idade, | ||
| "notas": notas, | ||
| "ativo": True, | ||
| } | ||
|
|
||
| alunos.append(aluno) | ||
| salvar(alunos) | ||
| return aluno | ||
|
|
||
|
|
||
| def listar_alunos() -> list[dict]: | ||
| """Lista todos os alunos cadastrados no sistema. | ||
|
|
||
| Returns: | ||
| list[dict]: Lista com todos os dicionários de alunos. | ||
| """ | ||
| return carregar() | ||
|
|
||
|
|
||
| def buscar_por_nome(nome: str) -> dict | None: | ||
| """Busca um aluno no sistema pelo nome. | ||
|
|
||
| A busca ignora diferenças entre letras maiúsculas e minúsculas. | ||
|
|
||
| Args: | ||
| nome (str): O nome do aluno a ser buscado. | ||
|
|
||
| Returns: | ||
| dict | None: O dicionário do aluno se encontrado, ou None caso contrário. | ||
| """ | ||
| for aluno in carregar(): | ||
| if aluno["nome"].lower() == nome.lower(): | ||
| return aluno | ||
| return None | ||
|
|
||
|
|
||
| def calcular_media_turma() -> float: | ||
| """Calcula a média geral de todas as notas de todos os alunos da turma. | ||
|
|
||
| Returns: | ||
| float: A média geral da turma. Retorna 0.0 se não houver notas. | ||
| """ | ||
| alunos = carregar() | ||
| if not alunos: | ||
| return 0.0 | ||
|
|
||
| total_notas = 0 | ||
| qtd_notas = 0 | ||
|
|
||
| for aluno in alunos: | ||
| total_notas += sum(aluno["notas"]) | ||
| qtd_notas += len(aluno["notas"]) | ||
|
|
||
| return total_notas / qtd_notas | ||
|
|
||
|
Comment on lines
+100
to
+112
|
||
|
|
||
| def exportar_relatorio() -> None: | ||
| """Gera um relatório estatístico da turma e salva em 'relatorio_turma.json'. | ||
|
|
||
| O relatório contém o total de alunos, a média geral da turma, e os dados | ||
| completos dos alunos com a maior e a menor média observadas. | ||
| """ | ||
| alunos = carregar() | ||
| if not alunos: | ||
| return | ||
|
|
||
| aluno_maior = alunos[0] | ||
| aluno_menor = alunos[0] | ||
|
|
||
| for aluno in alunos: | ||
| media_atual = sum(aluno["notas"]) / len(aluno["notas"]) | ||
| media_maior = sum(aluno_maior["notas"]) / len(aluno_maior["notas"]) | ||
| media_menor = sum(aluno_menor["notas"]) / len(aluno_menor["notas"]) | ||
|
|
||
|
Comment on lines
+127
to
+131
|
||
| if media_atual > media_maior: | ||
| aluno_maior = aluno | ||
| if media_atual < media_menor: | ||
| aluno_menor = aluno | ||
|
|
||
| # Ajustado para passar o "aluno" (objeto/dict completo) conforme pede o enunciado | ||
| relatorio = { | ||
| "total_alunos": len(alunos), | ||
| "media_geral": calcular_media_turma(), | ||
| "aluno_maior_media": aluno_maior, | ||
| "aluno_menor_media": aluno_menor, | ||
| } | ||
|
|
||
| with open("relatorio_turma.json", "w") as f: | ||
| json.dump(relatorio, f, indent=4) | ||
|
|
||
|
|
||
| # ===================================================================== | ||
| # DEMONSTRAÇÃO OBRIGATÓRIA | ||
| # ===================================================================== | ||
| if __name__ == "__main__": | ||
| print("--- INICIANDO SISTEMA DE CADASTRO ---") | ||
|
|
||
| # Limpa o arquivo para o teste rodar limpo | ||
| open(ARQUIVO, "w").close() | ||
|
|
||
| # 1. Cadastrar 4 alunos | ||
| print("\n[Passo 1] Cadastrando 4 alunos...") | ||
| cadastrar_aluno("Leticia", "leticia@email.com", 20, [8.0, 9.0]) | ||
| cadastrar_aluno("Rafael", "rafael@email.com", 21, [7.0, 6.0]) | ||
| cadastrar_aluno("Maria", "maria@email.com", 19, [10.0, 9.5]) | ||
| cadastrar_aluno("Lucas", "lucas@email.com", 22, [5.0, 6.5]) | ||
| print("Alunos cadastrados com sucesso!") | ||
|
|
||
| # 2. Listar alunos | ||
| print("\n[Passo 2] Listando alunos salvos:") | ||
| todos_alunos = listar_alunos() | ||
| for aluno in todos_alunos: | ||
| print(f"- ID: {aluno['id']} | Nome: {aluno['nome']}") | ||
|
|
||
| # 3. Buscar um aluno por nome | ||
| print("\n[Passo 3] Buscando pela 'Maria':") | ||
| aluno_encontrado = buscar_por_nome("Maria") | ||
| print(aluno_encontrado) | ||
|
|
||
| # 4. Exibir média da turma | ||
| print("\n[Passo 4] Calculando média geral da turma...") | ||
| media = calcular_media_turma() | ||
| print(f"Média da turma: {media:.2f}") | ||
|
|
||
| # 5. Exportar relatório | ||
| print("\n[Passo 5] Exportando relatório...") | ||
| exportar_relatorio() | ||
| print("Arquivo 'relatorio_turma.json' gerado com sucesso!") | ||
This file contains hidden or 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,26 @@ | ||
| { | ||
| "total_alunos": 4, | ||
| "media_geral": 7.625, | ||
| "aluno_maior_media": { | ||
| "id": 3, | ||
| "nome": "Maria", | ||
| "email": "maria@email.com", | ||
| "idade": 19, | ||
| "notas": [ | ||
| 10.0, | ||
| 9.5 | ||
| ], | ||
| "ativo": true | ||
| }, | ||
| "aluno_menor_media": { | ||
| "id": 4, | ||
| "nome": "Lucas", | ||
| "email": "lucas@email.com", | ||
| "idade": 22, | ||
| "notas": [ | ||
| 5.0, | ||
| 6.5 | ||
| ], | ||
| "ativo": true | ||
| } | ||
| } |
This file contains hidden or 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,72 @@ | ||
| # Atividade 1 - Calculadora de Operações | ||
| #Alunos: Leticia Alves e Rafael Nobrega de Lima | ||
|
|
||
| # Contexto: calculadora aritmética com 6 operações. Conceito central: dicionário simples + lambdas como valores. | ||
| import math | ||
|
|
||
| # Registry | ||
| calculadora_operacoes = {} | ||
|
|
||
| def calcular_depois(nome:str): | ||
| def decorator(classe): | ||
| calculadora_operacoes[nome] = classe | ||
| return classe | ||
| return decorator | ||
|
|
||
| # ---------------- OPERAÇÕES ---------------- # | ||
| @calcular_depois("soma") | ||
| class Soma: | ||
| def executar(self, a,b): | ||
| return a + b | ||
|
|
||
| @calcular_depois("subtracao") | ||
| class Subtracao: | ||
| def executar(self, a,b): | ||
| return a - b | ||
|
|
||
| @calcular_depois("divisao") | ||
| class Divisao: | ||
| def executar(self, a,b): | ||
| try: | ||
| return a / b | ||
| except ZeroDivisionError: | ||
| raise ValueError("Não é possível dividir por zero") | ||
|
|
||
| @calcular_depois("multiplicacao") | ||
| class Multiplicacao: | ||
| def executar(self, a,b): | ||
| return a * b | ||
|
|
||
| @calcular_depois("potenciacao") | ||
| class Potenciacao: | ||
| def executar(self, a,b): | ||
| return a ** b | ||
|
|
||
| @calcular_depois("raiz") | ||
| class Radiciacao: | ||
| def executar(self, a, b=None): | ||
|
|
||
| if a < 0: | ||
| raise ValueError("Não existe raiz real de número negativo") | ||
|
|
||
| return math.sqrt(a) | ||
|
|
||
|
|
||
| # ---------------- CALCULADORA ---------------- # | ||
| def calcular(operacao: str, a: float, b: float = None): | ||
| if operacao not in calculadora_operacoes: | ||
| raise ValueError(f"Operação {operacao} inválida!!") | ||
|
|
||
| classe_op = calculadora_operacoes[operacao]() | ||
| return classe_op.executar(a,b) | ||
|
|
||
| # ---------------- TESTES ---------------- # | ||
|
|
||
| if __name__ == "__main__": | ||
| print(calcular("soma", 10, 10)) | ||
| print(calcular("subtracao", 10, 3)) | ||
| print(calcular("multiplicacao", 9, 3)) | ||
| print(calcular("potenciacao", 2, 3)) | ||
| print(calcular("raiz", 25)) | ||
|
|
||
| # print(calcular("divisao", 10, 0)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.