File size: 822 Bytes
0f0ef8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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()
|