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()