From 56c8fbf0b0853431e20e7fd70b6a5c2ee27d73af Mon Sep 17 00:00:00 2001 From: Pedrinha21 Date: Thu, 28 May 2026 20:13:34 -0300 Subject: [PATCH 1/2] 28/05/2026 - Zaion --- Guia3/src/alternativa.py | 6 +++++- Guia3/src/pergunta.py | 17 +++++++++++++++-- Guia3/src/perguntadiscursiva.py | 13 +++++++++++-- Guia3/src/perguntamultiplaescolha.py | 9 ++++++++- Guia3/src/questionario.py | 11 ++++++++++- Guia3/src/resposta.py | 8 +++++++- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Guia3/src/alternativa.py b/Guia3/src/alternativa.py index 4dde61f..2a59bd9 100644 --- a/Guia3/src/alternativa.py +++ b/Guia3/src/alternativa.py @@ -1,4 +1,8 @@ from typing import List, Tuple, Dict class Alternativa: - pass \ No newline at end of file + def __init__(self, texto:str, correta: bool, explicacao: str): + self.texto = texto + self.correta = correta + self.explicacao = explicacao + \ No newline at end of file diff --git a/Guia3/src/pergunta.py b/Guia3/src/pergunta.py index 5b3763d..6f76bde 100644 --- a/Guia3/src/pergunta.py +++ b/Guia3/src/pergunta.py @@ -1,4 +1,17 @@ from typing import List, Tuple, Dict +from abc import ABC, abstractmethod -class Pergunta: - pass \ No newline at end of file +class Pergunta(ABC): + def __init__(self, texto: str, explicacao_geral: str): + self.texto = texto + self.explicacao_geral = explicacao_geral + + @abstractmethod + def validar_resposta(self, resposta): + pass + @abstractmethod + def get_explicacao(self): + return self.explicacao_geral + @abstractmethod + def get_tipo(self): + pass \ No newline at end of file diff --git a/Guia3/src/perguntadiscursiva.py b/Guia3/src/perguntadiscursiva.py index f4c26af..8adb606 100644 --- a/Guia3/src/perguntadiscursiva.py +++ b/Guia3/src/perguntadiscursiva.py @@ -1,4 +1,13 @@ from typing import List, Tuple, Dict +from pergunta import Pergunta -class PerguntaDiscursiva: - pass \ No newline at end of file +class PerguntaDiscursiva(Pergunta): + def __init__(self, resposta_esperada, case_sensitive): + self.resposta_esperada = resposta_esperada + self.case_sensitive = case_sensitive + + def validar_resposta(self,texto): + if texto == self.resposta_esperada: + return 1 + return 0 + \ No newline at end of file diff --git a/Guia3/src/perguntamultiplaescolha.py b/Guia3/src/perguntamultiplaescolha.py index bcbe94d..1c0bd54 100644 --- a/Guia3/src/perguntamultiplaescolha.py +++ b/Guia3/src/perguntamultiplaescolha.py @@ -1,4 +1,11 @@ from typing import List, Tuple, Dict class PerguntaMultiplaEscolha: - pass \ No newline at end of file + def __init__(self, alternativas): + self.alternativas = [] + + def validar_resposta(self, indice): + pass + + def get_alternativa_correta(): + pass \ No newline at end of file diff --git a/Guia3/src/questionario.py b/Guia3/src/questionario.py index 7525582..d00493f 100644 --- a/Guia3/src/questionario.py +++ b/Guia3/src/questionario.py @@ -1,4 +1,13 @@ from typing import List, Tuple, Dict class Questionario: - pass + def __init__(self, titulo: str, perguntas): + self.titulo = titulo + self.perguntas = list(perguntas) + + def adicionar_pergunta(Pergunta, self): + self.perguntas.append(Pergunta) + + def criar_attempt(usuario:str): + usuario + diff --git a/Guia3/src/resposta.py b/Guia3/src/resposta.py index 846d771..6a7221b 100644 --- a/Guia3/src/resposta.py +++ b/Guia3/src/resposta.py @@ -1,4 +1,10 @@ from typing import List, Tuple, Dict class Resposta: - pass \ No newline at end of file + def __init__(self, pergunta, esta_correta, pontuacao_obtida): + self.pergunta = pergunta + self.esta_correta = esta_correta + self.pontuacao_obtida = pontuacao_obtida + + def calcular_pontuacao(): + pass From cc942d829ab56da31eb9abfdc291953ed2cd6f99 Mon Sep 17 00:00:00 2001 From: Pedrinha21 Date: Fri, 29 May 2026 21:37:28 -0300 Subject: [PATCH 2/2] Acerto de 100% dos testes guia 3 29/05 Zaion --- Guia3/src/alternativa.py | 5 ++-- Guia3/src/pergunta.py | 5 ++-- Guia3/src/perguntadiscursiva.py | 23 +++++++++++------ Guia3/src/perguntamultiplaescolha.py | 26 +++++++++++++------ Guia3/src/questionario.py | 19 +++++++------- Guia3/src/resposta.py | 14 +++++----- Guia3/src/respostadiscursiva.py | 12 +++++++-- Guia3/src/respostaobjetiva.py | 13 ++++++++-- Guia3/src/tentativaquestionario.py | 38 +++++++++++++++++++++++++++- 9 files changed, 114 insertions(+), 41 deletions(-) diff --git a/Guia3/src/alternativa.py b/Guia3/src/alternativa.py index 2a59bd9..cdae2b5 100644 --- a/Guia3/src/alternativa.py +++ b/Guia3/src/alternativa.py @@ -1,8 +1,7 @@ from typing import List, Tuple, Dict class Alternativa: - def __init__(self, texto:str, correta: bool, explicacao: str): + def __init__(self, texto: str, correta: bool, explicacao: str = None): self.texto = texto self.correta = correta - self.explicacao = explicacao - \ No newline at end of file + self.explicacao = explicacao \ No newline at end of file diff --git a/Guia3/src/pergunta.py b/Guia3/src/pergunta.py index 6f76bde..9adaf46 100644 --- a/Guia3/src/pergunta.py +++ b/Guia3/src/pergunta.py @@ -2,16 +2,17 @@ from abc import ABC, abstractmethod class Pergunta(ABC): - def __init__(self, texto: str, explicacao_geral: str): + def __init__(self, texto: str, explicacao_geral: str = None): self.texto = texto self.explicacao_geral = explicacao_geral @abstractmethod def validar_resposta(self, resposta): pass - @abstractmethod + def get_explicacao(self): return self.explicacao_geral + @abstractmethod def get_tipo(self): pass \ No newline at end of file diff --git a/Guia3/src/perguntadiscursiva.py b/Guia3/src/perguntadiscursiva.py index 8adb606..be10e1e 100644 --- a/Guia3/src/perguntadiscursiva.py +++ b/Guia3/src/perguntadiscursiva.py @@ -1,13 +1,20 @@ from typing import List, Tuple, Dict -from pergunta import Pergunta +from .pergunta import Pergunta class PerguntaDiscursiva(Pergunta): - def __init__(self, resposta_esperada, case_sensitive): + def __init__(self, texto: str, resposta_esperada: str = None, case_sensitive: bool = False, explicacao_geral: str = None): + super().__init__(texto, explicacao_geral) self.resposta_esperada = resposta_esperada self.case_sensitive = case_sensitive - - def validar_resposta(self,texto): - if texto == self.resposta_esperada: - return 1 - return 0 - \ No newline at end of file + + def validar_resposta(self, texto: str) -> bool: + if self.resposta_esperada is None: + return False + + if self.case_sensitive: + return texto == self.resposta_esperada + + return texto.strip().lower() == self.resposta_esperada.strip().lower() + + def get_tipo(self): + return "discursiva" \ No newline at end of file diff --git a/Guia3/src/perguntamultiplaescolha.py b/Guia3/src/perguntamultiplaescolha.py index 1c0bd54..715fb61 100644 --- a/Guia3/src/perguntamultiplaescolha.py +++ b/Guia3/src/perguntamultiplaescolha.py @@ -1,11 +1,21 @@ from typing import List, Tuple, Dict +from .pergunta import Pergunta -class PerguntaMultiplaEscolha: - def __init__(self, alternativas): - self.alternativas = [] - - def validar_resposta(self, indice): - pass +class PerguntaMultiplaEscolha(Pergunta): + def __init__(self, texto: str, alternativas: list, explicacao_geral: str = None): + super().__init__(texto, explicacao_geral) + self.alternativas = alternativas - def get_alternativa_correta(): - pass \ No newline at end of file + def validar_resposta(self, indice: int) -> bool: + if indice < 0 or indice >= len(self.alternativas): + return False + return self.alternativas[indice].correta + + def get_alternativa_correta(self): + for alt in self.alternativas: + if alt.correta: + return alt + return None + + def get_tipo(self): + return "multipla_escolha" \ No newline at end of file diff --git a/Guia3/src/questionario.py b/Guia3/src/questionario.py index d00493f..75b6dd8 100644 --- a/Guia3/src/questionario.py +++ b/Guia3/src/questionario.py @@ -1,13 +1,14 @@ from typing import List, Tuple, Dict +from .tentativaquestionario import TentativaQuestionario + class Questionario: - def __init__(self, titulo: str, perguntas): + def __init__(self, titulo: str, perguntas=None): self.titulo = titulo - self.perguntas = list(perguntas) - - def adicionar_pergunta(Pergunta, self): - self.perguntas.append(Pergunta) - - def criar_attempt(usuario:str): - usuario - + self.perguntas = perguntas if perguntas else [] + + def adicionar_pergunta(self, pergunta): + self.perguntas.append(pergunta) + + def criar_attempt(self, usuario: str): + return TentativaQuestionario(self, usuario) \ No newline at end of file diff --git a/Guia3/src/resposta.py b/Guia3/src/resposta.py index 6a7221b..dbc5221 100644 --- a/Guia3/src/resposta.py +++ b/Guia3/src/resposta.py @@ -1,10 +1,12 @@ from typing import List, Tuple, Dict +from abc import ABC, abstractmethod -class Resposta: - def __init__(self, pergunta, esta_correta, pontuacao_obtida): +class Resposta(ABC): + def __init__(self, pergunta): self.pergunta = pergunta - self.esta_correta = esta_correta - self.pontuacao_obtida = pontuacao_obtida - - def calcular_pontuacao(): + self.esta_correta = False + self.pontuacao_obtida = 0.0 + + @abstractmethod + def calcular_pontuacao(self) -> float: pass diff --git a/Guia3/src/respostadiscursiva.py b/Guia3/src/respostadiscursiva.py index 4ea6dbb..9e15dac 100644 --- a/Guia3/src/respostadiscursiva.py +++ b/Guia3/src/respostadiscursiva.py @@ -1,4 +1,12 @@ from typing import List, Tuple, Dict +from .resposta import Resposta -class RespostaDiscursiva: - pass \ No newline at end of file +class RespostaDiscursiva(Resposta): + def __init__(self, pergunta, texto_resposta: str): + super().__init__(pergunta) + self.texto_resposta = texto_resposta + self.esta_correta = bool(self.pergunta.validar_resposta(self.texto_resposta)) + self.pontuacao_obtida = 1.0 if self.esta_correta else 0.0 + + def calcular_pontuacao(self) -> float: + return self.pontuacao_obtida \ No newline at end of file diff --git a/Guia3/src/respostaobjetiva.py b/Guia3/src/respostaobjetiva.py index 72ed2d0..e0d4426 100644 --- a/Guia3/src/respostaobjetiva.py +++ b/Guia3/src/respostaobjetiva.py @@ -1,4 +1,13 @@ from typing import List, Tuple, Dict +from .resposta import Resposta -class RespostaObjetiva: - pass \ No newline at end of file +class RespostaObjetiva(Resposta): + def __init__(self, pergunta, indice_escolhido: int): + super().__init__(pergunta) + self.indice_escolhido = indice_escolhido + self.alternativa_selecionada = None + self.esta_correta = self.pergunta.validar_resposta(self.indice_escolhido) + self.pontuacao_obtida = 1.0 if self.esta_correta else 0.0 + + def calcular_pontuacao(self) -> float: + return self.pontuacao_obtida \ No newline at end of file diff --git a/Guia3/src/tentativaquestionario.py b/Guia3/src/tentativaquestionario.py index 9947dd1..f01da3a 100644 --- a/Guia3/src/tentativaquestionario.py +++ b/Guia3/src/tentativaquestionario.py @@ -1,4 +1,40 @@ from typing import List, Tuple, Dict +from datetime import datetime +from .respostaobjetiva import RespostaObjetiva +from .respostadiscursiva import RespostaDiscursiva class TentativaQuestionario: - pass \ No newline at end of file + def __init__(self, questionario, usuario: str): + self.questionario = questionario + self.usuario = usuario + self.data_inicio = datetime.now() + self.data_fim = None + self.respostas = [] + self._finalizado = False + + def registrar_resposta(self, indice_pergunta: int, valor): + if self._finalizado: + return + + pergunta = self.questionario.perguntas[indice_pergunta] + + if hasattr(pergunta, "alternativas"): + resposta = RespostaObjetiva(pergunta, int(valor)) + else: + resposta = RespostaDiscursiva(pergunta, str(valor)) + + resposta.calcular_pontuacao() + self.respostas.append(resposta) + + def calcular_pontuacao(self): + return sum(r.pontuacao_obtida for r in self.respostas) + + def finalizar(self): + self.data_fim = datetime.now() + self._finalizado = True + pontuacao = self.calcular_pontuacao() + feedback = f"Usuário {self.usuario} fez {pontuacao} pontos" + return pontuacao, feedback + + def is_finalizado(self): + return self._finalizado \ No newline at end of file