IOI-RUN / listar_perguntas.py
Roudrigus's picture
Upload 82 files
0f0ef8d verified
raw
history blame contribute delete
822 Bytes
from banco import SessionLocal
from models import QuizPergunta, QuizResposta
def listar_perguntas_respostas():
db = SessionLocal()
try:
perguntas = db.query(QuizPergunta).filter(QuizPergunta.ativo == True).all()
for p in perguntas:
print(f"Pergunta (id={p.id}): {p.pergunta}")
respostas = db.query(QuizResposta).filter(QuizResposta.pergunta_id == p.id).all()
if not respostas:
print(" *** SEM RESPOSTAS CADASTRADAS ***")
continue
for r in respostas:
correta = " (correta)" if r.correta else ""
print(f" - Resposta (id={r.id}): {r.texto}{correta}")
print()
finally:
db.close()
if __name__ == "__main__":
listar_perguntas_respostas()