Download utils/quiz_handler.py from yekkala/SkillSync: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/spaces/yekkala/SkillSync/resolve/main/utils/quiz_handler.py
- Command line
-
hf download hf://spaces/yekkala/SkillSync/utils/quiz_handler.py
-
curl -L -o quiz_handler.py https://huggingface.co/spaces/yekkala/SkillSync/resolve/main/utils/quiz_handler.py
2.11 kB
| """ | |
| Quiz handling for SkillSync | |
| """ | |
| class QuizHandler: | |
| """Handles quiz evaluation and scoring""" | |
| def __init__(self, passing_score=80): | |
| self.passing_score = passing_score | |
| def evaluate_answers(self, questions, answers): | |
| """Evaluate quiz answers and return results""" | |
| correct_count = 0 | |
| results = [] | |
| for i, (answer, question) in enumerate(zip(answers, questions)): | |
| is_correct = answer == question['correct'] | |
| if is_correct: | |
| correct_count += 1 | |
| results.append({ | |
| "question_num": i + 1, | |
| "question": question['question'], | |
| "user_answer": question['options'][answer] if answer is not None else "Not answered", | |
| "correct_answer": question['options'][question['correct']], | |
| "is_correct": is_correct | |
| }) | |
| score = int((correct_count / len(questions)) * 100) if questions else 0 | |
| passed = score >= self.passing_score | |
| return { | |
| "score": score, | |
| "correct_count": correct_count, | |
| "total_questions": len(questions), | |
| "passed": passed, | |
| "results": results | |
| } | |
| def format_results(self, evaluation): | |
| """Format quiz results for display""" | |
| passed_icon = "π" if evaluation['passed'] else "π" | |
| passed_text = "**Passed!**" if evaluation['passed'] else "**Keep Learning!** You need 80% to pass." | |
| output = f""" | |
| ## Quiz Results | |
| **Score:** {evaluation['score']}% | |
| {passed_icon} {passed_text} | |
| **Correct Answers:** {evaluation['correct_count']}/{evaluation['total_questions']} | |
| --- | |
| ### Answer Review: | |
| """ | |
| for result in evaluation['results']: | |
| status = "β " if result['is_correct'] else "β" | |
| output += f"{status} **Q{result['question_num']}:** {result['question']}\n" | |
| output += f"- Your answer: *{result['user_answer']}*\n" | |
| output += f"- Correct answer: *{result['correct_answer']}*\n\n" | |
| return output | |