Spaces:
Running
Running
Add 3 files
Browse files- README.md +7 -5
- index.html +434 -19
- prompts.txt +0 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: python-quiz
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,434 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Python Quiz for Students</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.question-card {
|
| 11 |
+
transition: all 0.3s ease;
|
| 12 |
+
}
|
| 13 |
+
.question-card:hover {
|
| 14 |
+
transform: translateY(-3px);
|
| 15 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 16 |
+
}
|
| 17 |
+
.progress-bar {
|
| 18 |
+
transition: width 0.5s ease-in-out;
|
| 19 |
+
}
|
| 20 |
+
.fade-in {
|
| 21 |
+
animation: fadeIn 0.5s ease-in-out;
|
| 22 |
+
}
|
| 23 |
+
@keyframes fadeIn {
|
| 24 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 25 |
+
to { opacity: 1; transform: translateY(0); }
|
| 26 |
+
}
|
| 27 |
+
.code-block {
|
| 28 |
+
font-family: 'Courier New', Courier, monospace;
|
| 29 |
+
background-color: #f8f8f8;
|
| 30 |
+
border-radius: 4px;
|
| 31 |
+
padding: 10px;
|
| 32 |
+
border-left: 3px solid #3b82f6;
|
| 33 |
+
}
|
| 34 |
+
</style>
|
| 35 |
+
</head>
|
| 36 |
+
<body class="bg-gray-50 min-h-screen">
|
| 37 |
+
<div class="container mx-auto px-4 py-8">
|
| 38 |
+
<header class="text-center mb-12">
|
| 39 |
+
<h1 class="text-4xl font-bold text-blue-800 mb-2">Python Quiz</h1>
|
| 40 |
+
<p class="text-lg text-gray-600">Test your Python knowledge and get instant feedback</p>
|
| 41 |
+
<div class="w-24 h-1 bg-blue-500 mx-auto mt-4 rounded-full"></div>
|
| 42 |
+
</header>
|
| 43 |
+
|
| 44 |
+
<div class="max-w-3xl mx-auto">
|
| 45 |
+
<div id="quizContainer" class="bg-white rounded-xl shadow-lg p-6 mb-8 question-card">
|
| 46 |
+
<div class="flex justify-between items-center mb-6">
|
| 47 |
+
<h2 class="text-xl font-semibold text-gray-800">Question</h2>
|
| 48 |
+
<span id="questionCounter" class="bg-blue-100 text-blue-800 text-sm font-medium px-3 py-1 rounded-full">1/10</span>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<div id="questionContent" class="mb-6">
|
| 52 |
+
<p id="questionText" class="text-gray-700 mb-4"></p>
|
| 53 |
+
<div id="codeExample" class="code-block mb-4 hidden">
|
| 54 |
+
<pre id="codeContent" class="whitespace-pre-wrap"></pre>
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<div class="mb-6">
|
| 59 |
+
<label for="studentAnswer" class="block text-sm font-medium text-gray-700 mb-2">Your Answer:</label>
|
| 60 |
+
<textarea id="studentAnswer" rows="5" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Write your Python code or explanation here..."></textarea>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<div class="flex justify-between">
|
| 64 |
+
<button id="skipBtn" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 transition-colors duration-300">
|
| 65 |
+
<i class="fas fa-forward mr-2"></i>Skip
|
| 66 |
+
</button>
|
| 67 |
+
<button id="submitBtn" class="px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors duration-300">
|
| 68 |
+
<i class="fas fa-paper-plane mr-2"></i>Submit
|
| 69 |
+
</button>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<div id="resultContainer" class="bg-white rounded-xl shadow-lg p-6 mb-8 hidden fade-in">
|
| 74 |
+
<div class="text-center mb-6">
|
| 75 |
+
<h2 class="text-2xl font-bold text-gray-800 mb-2">Your Result</h2>
|
| 76 |
+
<p id="resultMessage" class="text-gray-600"></p>
|
| 77 |
+
</div>
|
| 78 |
+
|
| 79 |
+
<div class="mb-6">
|
| 80 |
+
<div class="flex justify-between mb-1">
|
| 81 |
+
<span class="text-sm font-medium text-gray-700">Answer Similarity</span>
|
| 82 |
+
<span id="similarityPercent" class="text-sm font-medium text-gray-700">0%</span>
|
| 83 |
+
</div>
|
| 84 |
+
<div class="w-full bg-gray-200 rounded-full h-2.5">
|
| 85 |
+
<div id="similarityBar" class="progress-bar h-2.5 rounded-full bg-blue-600" style="width: 0%"></div>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
|
| 89 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
| 90 |
+
<div>
|
| 91 |
+
<h3 class="font-medium text-gray-700 mb-2">Your Answer:</h3>
|
| 92 |
+
<div class="code-block">
|
| 93 |
+
<pre id="displayStudentAnswer" class="whitespace-pre-wrap"></pre>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
<div>
|
| 97 |
+
<h3 class="font-medium text-gray-700 mb-2">Expected Answer:</h3>
|
| 98 |
+
<div class="code-block">
|
| 99 |
+
<pre id="displayCorrectAnswer" class="whitespace-pre-wrap"></pre>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<div id="feedbackTips" class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6 hidden">
|
| 105 |
+
<h3 class="font-medium text-blue-800 mb-2">Tips for improvement:</h3>
|
| 106 |
+
<p id="improvementTips" class="text-blue-700"></p>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<div class="text-center">
|
| 110 |
+
<button id="nextQuestionBtn" class="px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors duration-300">
|
| 111 |
+
<i class="fas fa-arrow-right mr-2"></i>Next Question
|
| 112 |
+
</button>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
<div id="quizComplete" class="bg-white rounded-xl shadow-lg p-8 text-center hidden fade-in">
|
| 117 |
+
<div class="mb-6">
|
| 118 |
+
<i class="fas fa-trophy text-yellow-500 text-6xl mb-4"></i>
|
| 119 |
+
<h2 class="text-2xl font-bold text-gray-800 mb-2">Quiz Complete!</h2>
|
| 120 |
+
<p class="text-gray-600 mb-4">You've answered all the questions.</p>
|
| 121 |
+
</div>
|
| 122 |
+
|
| 123 |
+
<div class="bg-blue-50 rounded-lg p-6 mb-6 max-w-md mx-auto">
|
| 124 |
+
<h3 class="font-medium text-blue-800 mb-2">Your Final Score</h3>
|
| 125 |
+
<div class="text-4xl font-bold text-blue-600 mb-2" id="finalScore">0%</div>
|
| 126 |
+
<div class="w-full bg-gray-200 rounded-full h-2.5">
|
| 127 |
+
<div id="finalScoreBar" class="progress-bar h-2.5 rounded-full bg-blue-600" style="width: 0%"></div>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
|
| 131 |
+
<div class="flex justify-center gap-4">
|
| 132 |
+
<button id="restartQuizBtn" class="px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors duration-300">
|
| 133 |
+
<i class="fas fa-redo mr-2"></i>Restart Quiz
|
| 134 |
+
</button>
|
| 135 |
+
<button id="reviewAnswersBtn" class="px-6 py-2 border border-blue-600 text-blue-600 rounded-md hover:bg-blue-50 transition-colors duration-300">
|
| 136 |
+
<i class="fas fa-list-ul mr-2"></i>Review Answers
|
| 137 |
+
</button>
|
| 138 |
+
</div>
|
| 139 |
+
</div>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<script>
|
| 144 |
+
// Python questions database
|
| 145 |
+
const pythonQuestions = [
|
| 146 |
+
{
|
| 147 |
+
question: "Write a function to calculate the factorial of a number.",
|
| 148 |
+
codeExample: "def factorial(n):\n # Your code here",
|
| 149 |
+
answer: "def factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)",
|
| 150 |
+
tips: "Remember that factorial of 0 is 1. Use recursion for an elegant solution."
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
question: "How would you reverse a string in Python?",
|
| 154 |
+
codeExample: "my_string = 'hello'\n# Your code here",
|
| 155 |
+
answer: "my_string = 'hello'\nreversed_string = my_string[::-1]",
|
| 156 |
+
tips: "Python slicing is powerful. [::-1] means start at end of string and move backwards."
|
| 157 |
+
},
|
| 158 |
+
{
|
| 159 |
+
question: "Write a list comprehension to get squares of even numbers from 1 to 10.",
|
| 160 |
+
codeExample: "# Your list comprehension here",
|
| 161 |
+
answer: "[x**2 for x in range(1, 11) if x % 2 == 0]",
|
| 162 |
+
tips: "List comprehensions have three parts: output expression, input sequence, and optional condition."
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
question: "How do you check if a key exists in a dictionary?",
|
| 166 |
+
codeExample: "my_dict = {'a': 1, 'b': 2}\n# Your code here",
|
| 167 |
+
answer: "my_dict = {'a': 1, 'b': 2}\nif 'a' in my_dict:\n print('Key exists')",
|
| 168 |
+
tips: "The 'in' keyword is the Pythonic way to check for key existence in dictionaries."
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
question: "Write a lambda function to add 10 to a given number.",
|
| 172 |
+
codeExample: "# Your lambda function here",
|
| 173 |
+
answer: "add_ten = lambda x: x + 10",
|
| 174 |
+
tips: "Lambda functions are anonymous functions defined with the lambda keyword."
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
question: "How would you handle exceptions in Python?",
|
| 178 |
+
codeExample: "# Your exception handling code here",
|
| 179 |
+
answer: "try:\n # Code that might raise an exception\n x = 1 / 0\nexcept ZeroDivisionError:\n print('Cannot divide by zero')\nexcept Exception as e:\n print(f'An error occurred: {e}')",
|
| 180 |
+
tips: "Always catch specific exceptions before more general ones. Use 'as' to access the exception object."
|
| 181 |
+
},
|
| 182 |
+
{
|
| 183 |
+
question: "Write a function to check if a number is prime.",
|
| 184 |
+
codeExample: "def is_prime(n):\n # Your code here",
|
| 185 |
+
answer: "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
|
| 186 |
+
tips: "Optimize by checking divisors only up to the square root of the number."
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
question: "How would you merge two dictionaries in Python?",
|
| 190 |
+
codeExample: "dict1 = {'a': 1, 'b': 2}\ndict2 = {'c': 3, 'd': 4}\n# Your code here",
|
| 191 |
+
answer: "dict1 = {'a': 1, 'b': 2}\ndict2 = {'c': 3, 'd': 4}\nmerged = {**dict1, **dict2}",
|
| 192 |
+
tips: "In Python 3.5+, you can use the ** operator to unpack dictionaries. For older versions, use the update() method."
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
question: "Write a generator function to yield Fibonacci numbers.",
|
| 196 |
+
codeExample: "def fibonacci():\n # Your code here",
|
| 197 |
+
answer: "def fibonacci():\n a, b = 0, 1\n while True:\n yield a\n a, b = b, a + b",
|
| 198 |
+
tips: "Generators use yield instead of return. They maintain their state between calls."
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
question: "How would you remove duplicates from a list while preserving order?",
|
| 202 |
+
codeExample: "my_list = [1, 2, 2, 3, 4, 4, 5]\n# Your code here",
|
| 203 |
+
answer: "my_list = [1, 2, 2, 3, 4, 4, 5]\nunique_list = []\nseen = set()\nfor item in my_list:\n if item not in seen:\n unique_list.append(item)\n seen.add(item)",
|
| 204 |
+
tips: "Using a set for tracking seen items provides O(1) lookup time, making the solution efficient."
|
| 205 |
+
}
|
| 206 |
+
];
|
| 207 |
+
|
| 208 |
+
// Quiz state variables
|
| 209 |
+
let currentQuestionIndex = 0;
|
| 210 |
+
let shuffledQuestions = [];
|
| 211 |
+
let userAnswers = [];
|
| 212 |
+
let scores = [];
|
| 213 |
+
|
| 214 |
+
// DOM elements
|
| 215 |
+
const quizContainer = document.getElementById('quizContainer');
|
| 216 |
+
const resultContainer = document.getElementById('resultContainer');
|
| 217 |
+
const quizComplete = document.getElementById('quizComplete');
|
| 218 |
+
const questionText = document.getElementById('questionText');
|
| 219 |
+
const codeExample = document.getElementById('codeExample');
|
| 220 |
+
const codeContent = document.getElementById('codeContent');
|
| 221 |
+
const studentAnswer = document.getElementById('studentAnswer');
|
| 222 |
+
const submitBtn = document.getElementById('submitBtn');
|
| 223 |
+
const skipBtn = document.getElementById('skipBtn');
|
| 224 |
+
const nextQuestionBtn = document.getElementById('nextQuestionBtn');
|
| 225 |
+
const questionCounter = document.getElementById('questionCounter');
|
| 226 |
+
const displayStudentAnswer = document.getElementById('displayStudentAnswer');
|
| 227 |
+
const displayCorrectAnswer = document.getElementById('displayCorrectAnswer');
|
| 228 |
+
const similarityPercent = document.getElementById('similarityPercent');
|
| 229 |
+
const similarityBar = document.getElementById('similarityBar');
|
| 230 |
+
const feedbackTips = document.getElementById('feedbackTips');
|
| 231 |
+
const improvementTips = document.getElementById('improvementTips');
|
| 232 |
+
const resultMessage = document.getElementById('resultMessage');
|
| 233 |
+
const finalScore = document.getElementById('finalScore');
|
| 234 |
+
const finalScoreBar = document.getElementById('finalScoreBar');
|
| 235 |
+
const restartQuizBtn = document.getElementById('restartQuizBtn');
|
| 236 |
+
const reviewAnswersBtn = document.getElementById('reviewAnswersBtn');
|
| 237 |
+
|
| 238 |
+
// Initialize the quiz
|
| 239 |
+
function initQuiz() {
|
| 240 |
+
// Shuffle questions
|
| 241 |
+
shuffledQuestions = [...pythonQuestions].sort(() => Math.random() - 0.5);
|
| 242 |
+
currentQuestionIndex = 0;
|
| 243 |
+
userAnswers = [];
|
| 244 |
+
scores = [];
|
| 245 |
+
|
| 246 |
+
// Show first question
|
| 247 |
+
showQuestion();
|
| 248 |
+
quizContainer.classList.remove('hidden');
|
| 249 |
+
resultContainer.classList.add('hidden');
|
| 250 |
+
quizComplete.classList.add('hidden');
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// Display current question
|
| 254 |
+
function showQuestion() {
|
| 255 |
+
if (currentQuestionIndex >= shuffledQuestions.length) {
|
| 256 |
+
showQuizComplete();
|
| 257 |
+
return;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
const question = shuffledQuestions[currentQuestionIndex];
|
| 261 |
+
questionText.textContent = question.question;
|
| 262 |
+
|
| 263 |
+
if (question.codeExample) {
|
| 264 |
+
codeExample.classList.remove('hidden');
|
| 265 |
+
codeContent.textContent = question.codeExample;
|
| 266 |
+
} else {
|
| 267 |
+
codeExample.classList.add('hidden');
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
studentAnswer.value = '';
|
| 271 |
+
questionCounter.textContent = `${currentQuestionIndex + 1}/${shuffledQuestions.length}`;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// Calculate similarity between two strings (simple version)
|
| 275 |
+
function calculateSimilarity(str1, str2) {
|
| 276 |
+
// Remove whitespace and make lowercase for comparison
|
| 277 |
+
const cleanStr1 = str1.replace(/\s+/g, '').toLowerCase();
|
| 278 |
+
const cleanStr2 = str2.replace(/\s+/g, '').toLowerCase();
|
| 279 |
+
|
| 280 |
+
// If strings are identical
|
| 281 |
+
if (cleanStr1 === cleanStr2) return 100;
|
| 282 |
+
|
| 283 |
+
// If one string is empty
|
| 284 |
+
if (cleanStr1.length === 0 || cleanStr2.length === 0) return 0;
|
| 285 |
+
|
| 286 |
+
// Calculate Levenshtein distance
|
| 287 |
+
const distance = levenshteinDistance(cleanStr1, cleanStr2);
|
| 288 |
+
|
| 289 |
+
// Calculate similarity percentage
|
| 290 |
+
const maxLength = Math.max(cleanStr1.length, cleanStr2.length);
|
| 291 |
+
const similarity = (1 - distance / maxLength) * 100;
|
| 292 |
+
|
| 293 |
+
return Math.max(0, Math.min(100, similarity.toFixed(1)));
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
// Levenshtein distance algorithm
|
| 297 |
+
function levenshteinDistance(a, b) {
|
| 298 |
+
const matrix = [];
|
| 299 |
+
|
| 300 |
+
// Increment along the first column of each row
|
| 301 |
+
for (let i = 0; i <= b.length; i++) {
|
| 302 |
+
matrix[i] = [i];
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Increment each column in the first row
|
| 306 |
+
for (let j = 0; j <= a.length; j++) {
|
| 307 |
+
matrix[0][j] = j;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
// Fill in the rest of the matrix
|
| 311 |
+
for (let i = 1; i <= b.length; i++) {
|
| 312 |
+
for (let j = 1; j <= a.length; j++) {
|
| 313 |
+
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
| 314 |
+
matrix[i][j] = matrix[i - 1][j - 1];
|
| 315 |
+
} else {
|
| 316 |
+
matrix[i][j] = Math.min(
|
| 317 |
+
matrix[i - 1][j - 1] + 1, // substitution
|
| 318 |
+
matrix[i][j - 1] + 1, // insertion
|
| 319 |
+
matrix[i - 1][j] + 1 // deletion
|
| 320 |
+
);
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
return matrix[b.length][a.length];
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// Show result after submission
|
| 329 |
+
function showResult() {
|
| 330 |
+
const question = shuffledQuestions[currentQuestionIndex];
|
| 331 |
+
const userAnswer = studentAnswer.value.trim();
|
| 332 |
+
const correctAnswer = question.answer;
|
| 333 |
+
|
| 334 |
+
// Calculate similarity score
|
| 335 |
+
const similarityScore = calculateSimilarity(userAnswer, correctAnswer);
|
| 336 |
+
|
| 337 |
+
// Store user answer and score
|
| 338 |
+
userAnswers.push({
|
| 339 |
+
question: question.question,
|
| 340 |
+
userAnswer: userAnswer,
|
| 341 |
+
correctAnswer: correctAnswer,
|
| 342 |
+
score: similarityScore
|
| 343 |
+
});
|
| 344 |
+
scores.push(similarityScore);
|
| 345 |
+
|
| 346 |
+
// Display results
|
| 347 |
+
displayStudentAnswer.textContent = userAnswer || "No answer provided";
|
| 348 |
+
displayCorrectAnswer.textContent = correctAnswer;
|
| 349 |
+
similarityPercent.textContent = `${similarityScore}%`;
|
| 350 |
+
similarityBar.style.width = `${similarityScore}%`;
|
| 351 |
+
|
| 352 |
+
// Set color based on score
|
| 353 |
+
if (similarityScore >= 80) {
|
| 354 |
+
similarityBar.classList.remove('bg-red-600', 'bg-yellow-500');
|
| 355 |
+
similarityBar.classList.add('bg-green-500');
|
| 356 |
+
resultMessage.textContent = "Excellent! Your answer is very close to the expected solution.";
|
| 357 |
+
} else if (similarityScore >= 50) {
|
| 358 |
+
similarityBar.classList.remove('bg-green-500', 'bg-red-600');
|
| 359 |
+
similarityBar.classList.add('bg-yellow-500');
|
| 360 |
+
resultMessage.textContent = "Good try! Your answer has some similarities with the expected solution.";
|
| 361 |
+
} else {
|
| 362 |
+
similarityBar.classList.remove('bg-green-500', 'bg-yellow-500');
|
| 363 |
+
similarityBar.classList.add('bg-red-600');
|
| 364 |
+
resultMessage.textContent = "Keep practicing! Review the expected solution to improve.";
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// Show improvement tips if available
|
| 368 |
+
if (question.tips) {
|
| 369 |
+
improvementTips.textContent = question.tips;
|
| 370 |
+
feedbackTips.classList.remove('hidden');
|
| 371 |
+
} else {
|
| 372 |
+
feedbackTips.classList.add('hidden');
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
// Switch to result view
|
| 376 |
+
quizContainer.classList.add('hidden');
|
| 377 |
+
resultContainer.classList.remove('hidden');
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
// Move to next question
|
| 381 |
+
function nextQuestion() {
|
| 382 |
+
currentQuestionIndex++;
|
| 383 |
+
if (currentQuestionIndex < shuffledQuestions.length) {
|
| 384 |
+
showQuestion();
|
| 385 |
+
quizContainer.classList.remove('hidden');
|
| 386 |
+
resultContainer.classList.add('hidden');
|
| 387 |
+
} else {
|
| 388 |
+
showQuizComplete();
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
// Show quiz completion screen
|
| 393 |
+
function showQuizComplete() {
|
| 394 |
+
// Calculate average score
|
| 395 |
+
const averageScore = scores.reduce((a, b) => a + b, 0) / scores.length;
|
| 396 |
+
|
| 397 |
+
// Display final score
|
| 398 |
+
finalScore.textContent = `${averageScore.toFixed(1)}%`;
|
| 399 |
+
finalScoreBar.style.width = `${averageScore}%`;
|
| 400 |
+
|
| 401 |
+
// Set color based on score
|
| 402 |
+
if (averageScore >= 80) {
|
| 403 |
+
finalScoreBar.classList.remove('bg-red-600', 'bg-yellow-500');
|
| 404 |
+
finalScoreBar.classList.add('bg-green-500');
|
| 405 |
+
} else if (averageScore >= 50) {
|
| 406 |
+
finalScoreBar.classList.remove('bg-green-500', 'bg-red-600');
|
| 407 |
+
finalScoreBar.classList.add('bg-yellow-500');
|
| 408 |
+
} else {
|
| 409 |
+
finalScoreBar.classList.remove('bg-green-500', 'bg-yellow-500');
|
| 410 |
+
finalScoreBar.classList.add('bg-red-600');
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
// Show completion screen
|
| 414 |
+
quizContainer.classList.add('hidden');
|
| 415 |
+
resultContainer.classList.add('hidden');
|
| 416 |
+
quizComplete.classList.remove('hidden');
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// Event listeners
|
| 420 |
+
submitBtn.addEventListener('click', showResult);
|
| 421 |
+
skipBtn.addEventListener('click', nextQuestion);
|
| 422 |
+
nextQuestionBtn.addEventListener('click', nextQuestion);
|
| 423 |
+
restartQuizBtn.addEventListener('click', initQuiz);
|
| 424 |
+
|
| 425 |
+
// Review answers button would typically show a summary of all questions and answers
|
| 426 |
+
reviewAnswersBtn.addEventListener('click', () => {
|
| 427 |
+
alert('Review functionality would show all questions and your answers here.');
|
| 428 |
+
});
|
| 429 |
+
|
| 430 |
+
// Initialize the quiz when page loads
|
| 431 |
+
document.addEventListener('DOMContentLoaded', initQuiz);
|
| 432 |
+
</script>
|
| 433 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=karaltan/python-quiz" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 434 |
+
</html>
|
prompts.txt
ADDED
|
File without changes
|