Spaces:
Running
Running
Add 2 files
Browse files- index.html +152 -25
- prompts.txt +1 -0
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Python Quiz
|
| 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>
|
|
@@ -31,17 +31,32 @@
|
|
| 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">
|
| 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-
|
| 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>
|
|
@@ -55,9 +70,21 @@
|
|
| 55 |
</div>
|
| 56 |
</div>
|
| 57 |
|
| 58 |
-
<div class="mb-
|
| 59 |
-
<
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</div>
|
| 62 |
|
| 63 |
<div class="flex justify-between">
|
|
@@ -88,13 +115,13 @@
|
|
| 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
|
| 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
|
| 98 |
<div class="code-block">
|
| 99 |
<pre id="displayCorrectAnswer" class="whitespace-pre-wrap"></pre>
|
| 100 |
</div>
|
|
@@ -140,6 +167,8 @@
|
|
| 140 |
</div>
|
| 141 |
</div>
|
| 142 |
|
|
|
|
|
|
|
| 143 |
<script>
|
| 144 |
// Python questions database
|
| 145 |
const pythonQuestions = [
|
|
@@ -147,61 +176,71 @@
|
|
| 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 |
|
|
@@ -210,6 +249,7 @@
|
|
| 210 |
let shuffledQuestions = [];
|
| 211 |
let userAnswers = [];
|
| 212 |
let scores = [];
|
|
|
|
| 213 |
|
| 214 |
// DOM elements
|
| 215 |
const quizContainer = document.getElementById('quizContainer');
|
|
@@ -218,7 +258,6 @@
|
|
| 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');
|
|
@@ -234,6 +273,31 @@
|
|
| 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() {
|
|
@@ -248,6 +312,11 @@
|
|
| 248 |
quizContainer.classList.remove('hidden');
|
| 249 |
resultContainer.classList.add('hidden');
|
| 250 |
quizComplete.classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
|
| 253 |
// Display current question
|
|
@@ -267,10 +336,53 @@
|
|
| 267 |
codeExample.classList.add('hidden');
|
| 268 |
}
|
| 269 |
|
| 270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -327,8 +439,10 @@
|
|
| 327 |
|
| 328 |
// Show result after submission
|
| 329 |
function showResult() {
|
|
|
|
|
|
|
| 330 |
const question = shuffledQuestions[currentQuestionIndex];
|
| 331 |
-
const userAnswer =
|
| 332 |
const correctAnswer = question.answer;
|
| 333 |
|
| 334 |
// Calculate similarity score
|
|
@@ -339,7 +453,8 @@
|
|
| 339 |
question: question.question,
|
| 340 |
userAnswer: userAnswer,
|
| 341 |
correctAnswer: correctAnswer,
|
| 342 |
-
score: similarityScore
|
|
|
|
| 343 |
});
|
| 344 |
scores.push(similarityScore);
|
| 345 |
|
|
@@ -421,14 +536,26 @@
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
});
|
| 429 |
|
| 430 |
// Initialize the quiz when page loads
|
| 431 |
-
document.addEventListener('DOMContentLoaded',
|
|
|
|
|
|
|
|
|
|
| 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>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Python Quiz with Code Editor</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>
|
|
|
|
| 31 |
padding: 10px;
|
| 32 |
border-left: 3px solid #3b82f6;
|
| 33 |
}
|
| 34 |
+
#editorContainer {
|
| 35 |
+
height: 300px;
|
| 36 |
+
border: 1px solid #e5e7eb;
|
| 37 |
+
border-radius: 0.375rem;
|
| 38 |
+
overflow: hidden;
|
| 39 |
+
}
|
| 40 |
+
.output-container {
|
| 41 |
+
background-color: #1e1e1e;
|
| 42 |
+
color: #d4d4d4;
|
| 43 |
+
font-family: monospace;
|
| 44 |
+
padding: 10px;
|
| 45 |
+
border-radius: 0.375rem;
|
| 46 |
+
height: 100px;
|
| 47 |
+
overflow-y: auto;
|
| 48 |
+
}
|
| 49 |
</style>
|
| 50 |
</head>
|
| 51 |
<body class="bg-gray-50 min-h-screen">
|
| 52 |
<div class="container mx-auto px-4 py-8">
|
| 53 |
<header class="text-center mb-12">
|
| 54 |
+
<h1 class="text-4xl font-bold text-blue-800 mb-2">Python Code Quiz</h1>
|
| 55 |
+
<p class="text-lg text-gray-600">Write, test and submit your Python code directly in the editor</p>
|
| 56 |
<div class="w-24 h-1 bg-blue-500 mx-auto mt-4 rounded-full"></div>
|
| 57 |
</header>
|
| 58 |
|
| 59 |
+
<div class="max-w-5xl mx-auto">
|
| 60 |
<div id="quizContainer" class="bg-white rounded-xl shadow-lg p-6 mb-8 question-card">
|
| 61 |
<div class="flex justify-between items-center mb-6">
|
| 62 |
<h2 class="text-xl font-semibold text-gray-800">Question</h2>
|
|
|
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
|
| 73 |
+
<div class="mb-4">
|
| 74 |
+
<div class="flex justify-between items-center mb-2">
|
| 75 |
+
<label class="block text-sm font-medium text-gray-700">Code Editor:</label>
|
| 76 |
+
<button id="runCodeBtn" class="px-3 py-1 bg-green-600 text-white text-sm rounded-md hover:bg-green-700 transition-colors duration-300">
|
| 77 |
+
<i class="fas fa-play mr-1"></i> Run Code
|
| 78 |
+
</button>
|
| 79 |
+
</div>
|
| 80 |
+
<div id="editorContainer"></div>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
<div class="mb-4">
|
| 84 |
+
<label class="block text-sm font-medium text-gray-700 mb-2">Output:</label>
|
| 85 |
+
<div id="outputContainer" class="output-container">
|
| 86 |
+
<div id="outputContent">Output will appear here...</div>
|
| 87 |
+
</div>
|
| 88 |
</div>
|
| 89 |
|
| 90 |
<div class="flex justify-between">
|
|
|
|
| 115 |
|
| 116 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
| 117 |
<div>
|
| 118 |
+
<h3 class="font-medium text-gray-700 mb-2">Your Solution:</h3>
|
| 119 |
<div class="code-block">
|
| 120 |
<pre id="displayStudentAnswer" class="whitespace-pre-wrap"></pre>
|
| 121 |
</div>
|
| 122 |
</div>
|
| 123 |
<div>
|
| 124 |
+
<h3 class="font-medium text-gray-700 mb-2">Expected Solution:</h3>
|
| 125 |
<div class="code-block">
|
| 126 |
<pre id="displayCorrectAnswer" class="whitespace-pre-wrap"></pre>
|
| 127 |
</div>
|
|
|
|
| 167 |
</div>
|
| 168 |
</div>
|
| 169 |
|
| 170 |
+
<!-- Load Monaco Editor -->
|
| 171 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script>
|
| 172 |
<script>
|
| 173 |
// Python questions database
|
| 174 |
const pythonQuestions = [
|
|
|
|
| 176 |
question: "Write a function to calculate the factorial of a number.",
|
| 177 |
codeExample: "def factorial(n):\n # Your code here",
|
| 178 |
answer: "def factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)",
|
| 179 |
+
tips: "Remember that factorial of 0 is 1. Use recursion for an elegant solution.",
|
| 180 |
+
testCase: "print(factorial(5)) # Expected output: 120"
|
| 181 |
},
|
| 182 |
{
|
| 183 |
question: "How would you reverse a string in Python?",
|
| 184 |
codeExample: "my_string = 'hello'\n# Your code here",
|
| 185 |
answer: "my_string = 'hello'\nreversed_string = my_string[::-1]",
|
| 186 |
+
tips: "Python slicing is powerful. [::-1] means start at end of string and move backwards.",
|
| 187 |
+
testCase: "print(reversed_string) # Expected output: olleh"
|
| 188 |
},
|
| 189 |
{
|
| 190 |
question: "Write a list comprehension to get squares of even numbers from 1 to 10.",
|
| 191 |
codeExample: "# Your list comprehension here",
|
| 192 |
answer: "[x**2 for x in range(1, 11) if x % 2 == 0]",
|
| 193 |
+
tips: "List comprehensions have three parts: output expression, input sequence, and optional condition.",
|
| 194 |
+
testCase: "print(squares) # Expected output: [4, 16, 36, 64, 100]"
|
| 195 |
},
|
| 196 |
{
|
| 197 |
question: "How do you check if a key exists in a dictionary?",
|
| 198 |
codeExample: "my_dict = {'a': 1, 'b': 2}\n# Your code here",
|
| 199 |
answer: "my_dict = {'a': 1, 'b': 2}\nif 'a' in my_dict:\n print('Key exists')",
|
| 200 |
+
tips: "The 'in' keyword is the Pythonic way to check for key existence in dictionaries.",
|
| 201 |
+
testCase: "# Should print 'Key exists' if 'a' is in my_dict"
|
| 202 |
},
|
| 203 |
{
|
| 204 |
question: "Write a lambda function to add 10 to a given number.",
|
| 205 |
codeExample: "# Your lambda function here",
|
| 206 |
answer: "add_ten = lambda x: x + 10",
|
| 207 |
+
tips: "Lambda functions are anonymous functions defined with the lambda keyword.",
|
| 208 |
+
testCase: "print(add_ten(5)) # Expected output: 15"
|
| 209 |
},
|
| 210 |
{
|
| 211 |
question: "How would you handle exceptions in Python?",
|
| 212 |
codeExample: "# Your exception handling code here",
|
| 213 |
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}')",
|
| 214 |
+
tips: "Always catch specific exceptions before more general ones. Use 'as' to access the exception object.",
|
| 215 |
+
testCase: "# Should print 'Cannot divide by zero'"
|
| 216 |
},
|
| 217 |
{
|
| 218 |
question: "Write a function to check if a number is prime.",
|
| 219 |
codeExample: "def is_prime(n):\n # Your code here",
|
| 220 |
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",
|
| 221 |
+
tips: "Optimize by checking divisors only up to the square root of the number.",
|
| 222 |
+
testCase: "print(is_prime(7)) # Expected output: True\nprint(is_prime(4)) # Expected output: False"
|
| 223 |
},
|
| 224 |
{
|
| 225 |
question: "How would you merge two dictionaries in Python?",
|
| 226 |
codeExample: "dict1 = {'a': 1, 'b': 2}\ndict2 = {'c': 3, 'd': 4}\n# Your code here",
|
| 227 |
answer: "dict1 = {'a': 1, 'b': 2}\ndict2 = {'c': 3, 'd': 4}\nmerged = {**dict1, **dict2}",
|
| 228 |
+
tips: "In Python 3.5+, you can use the ** operator to unpack dictionaries. For older versions, use the update() method.",
|
| 229 |
+
testCase: "print(merged) # Expected output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}"
|
| 230 |
},
|
| 231 |
{
|
| 232 |
question: "Write a generator function to yield Fibonacci numbers.",
|
| 233 |
codeExample: "def fibonacci():\n # Your code here",
|
| 234 |
answer: "def fibonacci():\n a, b = 0, 1\n while True:\n yield a\n a, b = b, a + b",
|
| 235 |
+
tips: "Generators use yield instead of return. They maintain their state between calls.",
|
| 236 |
+
testCase: "fib = fibonacci()\nprint([next(fib) for _ in range(10)]) # Expected output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]"
|
| 237 |
},
|
| 238 |
{
|
| 239 |
question: "How would you remove duplicates from a list while preserving order?",
|
| 240 |
codeExample: "my_list = [1, 2, 2, 3, 4, 4, 5]\n# Your code here",
|
| 241 |
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)",
|
| 242 |
+
tips: "Using a set for tracking seen items provides O(1) lookup time, making the solution efficient.",
|
| 243 |
+
testCase: "print(unique_list) # Expected output: [1, 2, 3, 4, 5]"
|
| 244 |
}
|
| 245 |
];
|
| 246 |
|
|
|
|
| 249 |
let shuffledQuestions = [];
|
| 250 |
let userAnswers = [];
|
| 251 |
let scores = [];
|
| 252 |
+
let editor = null;
|
| 253 |
|
| 254 |
// DOM elements
|
| 255 |
const quizContainer = document.getElementById('quizContainer');
|
|
|
|
| 258 |
const questionText = document.getElementById('questionText');
|
| 259 |
const codeExample = document.getElementById('codeExample');
|
| 260 |
const codeContent = document.getElementById('codeContent');
|
|
|
|
| 261 |
const submitBtn = document.getElementById('submitBtn');
|
| 262 |
const skipBtn = document.getElementById('skipBtn');
|
| 263 |
const nextQuestionBtn = document.getElementById('nextQuestionBtn');
|
|
|
|
| 273 |
const finalScoreBar = document.getElementById('finalScoreBar');
|
| 274 |
const restartQuizBtn = document.getElementById('restartQuizBtn');
|
| 275 |
const reviewAnswersBtn = document.getElementById('reviewAnswersBtn');
|
| 276 |
+
const runCodeBtn = document.getElementById('runCodeBtn');
|
| 277 |
+
const outputContent = document.getElementById('outputContent');
|
| 278 |
+
|
| 279 |
+
// Initialize Monaco Editor
|
| 280 |
+
function initEditor() {
|
| 281 |
+
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs' }});
|
| 282 |
+
|
| 283 |
+
require(['vs/editor/editor.main'], function() {
|
| 284 |
+
editor = monaco.editor.create(document.getElementById('editorContainer'), {
|
| 285 |
+
value: '',
|
| 286 |
+
language: 'python',
|
| 287 |
+
theme: 'vs-dark',
|
| 288 |
+
automaticLayout: true,
|
| 289 |
+
minimap: {
|
| 290 |
+
enabled: false
|
| 291 |
+
},
|
| 292 |
+
fontSize: 14,
|
| 293 |
+
scrollBeyondLastLine: false,
|
| 294 |
+
renderWhitespace: 'selection',
|
| 295 |
+
roundedSelection: true,
|
| 296 |
+
autoIndent: 'full',
|
| 297 |
+
tabSize: 4
|
| 298 |
+
});
|
| 299 |
+
});
|
| 300 |
+
}
|
| 301 |
|
| 302 |
// Initialize the quiz
|
| 303 |
function initQuiz() {
|
|
|
|
| 312 |
quizContainer.classList.remove('hidden');
|
| 313 |
resultContainer.classList.add('hidden');
|
| 314 |
quizComplete.classList.add('hidden');
|
| 315 |
+
|
| 316 |
+
// Initialize editor if not already done
|
| 317 |
+
if (!editor) {
|
| 318 |
+
initEditor();
|
| 319 |
+
}
|
| 320 |
}
|
| 321 |
|
| 322 |
// Display current question
|
|
|
|
| 336 |
codeExample.classList.add('hidden');
|
| 337 |
}
|
| 338 |
|
| 339 |
+
// Set initial editor content
|
| 340 |
+
if (editor) {
|
| 341 |
+
editor.setValue(question.codeExample || '# Write your solution here');
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
// Clear output
|
| 345 |
+
outputContent.textContent = 'Output will appear here...';
|
| 346 |
+
|
| 347 |
questionCounter.textContent = `${currentQuestionIndex + 1}/${shuffledQuestions.length}`;
|
| 348 |
}
|
| 349 |
|
| 350 |
+
// Run Python code in the editor
|
| 351 |
+
function runPythonCode() {
|
| 352 |
+
if (!editor) return;
|
| 353 |
+
|
| 354 |
+
const code = editor.getValue();
|
| 355 |
+
outputContent.textContent = 'Running code...';
|
| 356 |
+
|
| 357 |
+
// In a real implementation, you would send this to a Python backend
|
| 358 |
+
// For this demo, we'll simulate execution with the test case
|
| 359 |
+
setTimeout(() => {
|
| 360 |
+
const question = shuffledQuestions[currentQuestionIndex];
|
| 361 |
+
if (question.testCase) {
|
| 362 |
+
outputContent.textContent = `>>> ${question.testCase}\n${getExpectedOutput(question)}`;
|
| 363 |
+
} else {
|
| 364 |
+
outputContent.textContent = "Code executed (simulated). Check your solution against the expected output when you submit.";
|
| 365 |
+
}
|
| 366 |
+
}, 1000);
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
// Helper function to get expected output for demo purposes
|
| 370 |
+
function getExpectedOutput(question) {
|
| 371 |
+
switch(currentQuestionIndex) {
|
| 372 |
+
case 0: return "120";
|
| 373 |
+
case 1: return "olleh";
|
| 374 |
+
case 2: return "[4, 16, 36, 64, 100]";
|
| 375 |
+
case 3: return "Key exists";
|
| 376 |
+
case 4: return "15";
|
| 377 |
+
case 5: return "Cannot divide by zero";
|
| 378 |
+
case 6: return "True\nFalse";
|
| 379 |
+
case 7: return "{'a': 1, 'b': 2, 'c': 3, 'd': 4}";
|
| 380 |
+
case 8: return "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]";
|
| 381 |
+
case 9: return "[1, 2, 3, 4, 5]";
|
| 382 |
+
default: return "Expected output";
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
// Calculate similarity between two strings (simple version)
|
| 387 |
function calculateSimilarity(str1, str2) {
|
| 388 |
// Remove whitespace and make lowercase for comparison
|
|
|
|
| 439 |
|
| 440 |
// Show result after submission
|
| 441 |
function showResult() {
|
| 442 |
+
if (!editor) return;
|
| 443 |
+
|
| 444 |
const question = shuffledQuestions[currentQuestionIndex];
|
| 445 |
+
const userAnswer = editor.getValue().trim();
|
| 446 |
const correctAnswer = question.answer;
|
| 447 |
|
| 448 |
// Calculate similarity score
|
|
|
|
| 453 |
question: question.question,
|
| 454 |
userAnswer: userAnswer,
|
| 455 |
correctAnswer: correctAnswer,
|
| 456 |
+
score: similarityScore,
|
| 457 |
+
output: outputContent.textContent
|
| 458 |
});
|
| 459 |
scores.push(similarityScore);
|
| 460 |
|
|
|
|
| 536 |
skipBtn.addEventListener('click', nextQuestion);
|
| 537 |
nextQuestionBtn.addEventListener('click', nextQuestion);
|
| 538 |
restartQuizBtn.addEventListener('click', initQuiz);
|
| 539 |
+
runCodeBtn.addEventListener('click', runPythonCode);
|
| 540 |
|
| 541 |
// Review answers button would typically show a summary of all questions and answers
|
| 542 |
reviewAnswersBtn.addEventListener('click', () => {
|
| 543 |
+
let reviewContent = "Review of your answers:\n\n";
|
| 544 |
+
userAnswers.forEach((answer, index) => {
|
| 545 |
+
reviewContent += `Question ${index + 1}: ${answer.question}\n`;
|
| 546 |
+
reviewContent += `Your Answer:\n${answer.userAnswer}\n\n`;
|
| 547 |
+
reviewContent += `Score: ${answer.score}%\n\n`;
|
| 548 |
+
reviewContent += "--------------------------------\n\n";
|
| 549 |
+
});
|
| 550 |
+
|
| 551 |
+
alert(reviewContent);
|
| 552 |
});
|
| 553 |
|
| 554 |
// Initialize the quiz when page loads
|
| 555 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 556 |
+
initEditor();
|
| 557 |
+
initQuiz();
|
| 558 |
+
});
|
| 559 |
</script>
|
| 560 |
<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>
|
| 561 |
</html>
|
prompts.txt
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
python editörü emmed
|