dwellnick commited on
Commit
8dee836
·
verified ·
1 Parent(s): fe607c9

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +854 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Python Knowledge Test
3
- emoji:
4
- colorFrom: indigo
5
- colorTo: gray
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-knowledge-test
3
+ emoji: 🐳
4
+ colorFrom: blue
5
+ colorTo: blue
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,854 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Knowledge Test</title>
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
8
+ <style>
9
+ :root {
10
+ --primary-color: #3776ab;
11
+ --secondary-color: #ffd43b;
12
+ --dark-color: #306998;
13
+ --light-color: #f8f9fa;
14
+ --success-color: #28a745;
15
+ --danger-color: #dc3545;
16
+ --warning-color: #ffc107;
17
+ --info-color: #17a2b8;
18
+ }
19
+
20
+ * {
21
+ box-sizing: border-box;
22
+ margin: 0;
23
+ padding: 0;
24
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
25
+ }
26
+
27
+ body {
28
+ background-color: #f5f5f5;
29
+ color: #333;
30
+ line-height: 1.6;
31
+ }
32
+
33
+ .container {
34
+ max-width: 800px;
35
+ margin: 0 auto;
36
+ padding: 20px;
37
+ }
38
+
39
+ header {
40
+ background-color: var(--primary-color);
41
+ color: white;
42
+ padding: 20px 0;
43
+ text-align: center;
44
+ border-radius: 8px 8px 0 0;
45
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
46
+ margin-bottom: 2rem;
47
+ }
48
+
49
+ header h1 {
50
+ font-size: 2.5rem;
51
+ margin-bottom: 10px;
52
+ }
53
+
54
+ header p {
55
+ font-size: 1.1rem;
56
+ opacity: 0.9;
57
+ }
58
+
59
+ .python-icon {
60
+ font-size: 3rem;
61
+ margin-bottom: 10px;
62
+ color: var(--secondary-color);
63
+ }
64
+
65
+ .quiz-container {
66
+ background-color: white;
67
+ border-radius: 8px;
68
+ padding: 30px;
69
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
70
+ margin-bottom: 2rem;
71
+ }
72
+
73
+ .question-counter {
74
+ font-size: 1.1rem;
75
+ font-weight: bold;
76
+ color: var(--primary-color);
77
+ margin-bottom: 20px;
78
+ display: flex;
79
+ justify-content: space-between;
80
+ align-items: center;
81
+ }
82
+
83
+ .progress-bar {
84
+ height: 8px;
85
+ background-color: #e9ecef;
86
+ border-radius: 4px;
87
+ overflow: hidden;
88
+ flex-grow: 1;
89
+ margin-left: 20px;
90
+ }
91
+
92
+ .progress {
93
+ height: 100%;
94
+ background-color: var(--primary-color);
95
+ width: 0%;
96
+ transition: width 0.3s ease;
97
+ }
98
+
99
+ .question {
100
+ font-size: 1.2rem;
101
+ font-weight: 500;
102
+ margin-bottom: 1.5rem;
103
+ }
104
+
105
+ .options {
106
+ display: grid;
107
+ grid-template-columns: 1fr;
108
+ gap: 12px;
109
+ margin-bottom: 1.5rem;
110
+ }
111
+
112
+ .option {
113
+ background-color: var(--light-color);
114
+ padding: 15px;
115
+ border-radius: 6px;
116
+ cursor: pointer;
117
+ transition: all 0.3s ease;
118
+ border: 2px solid transparent;
119
+ display: flex;
120
+ align-items: center;
121
+ }
122
+
123
+ .option:hover {
124
+ background-color: #e2e6ea;
125
+ transform: translateY(-2px);
126
+ }
127
+
128
+ .option.selected {
129
+ background-color: #e3f2fd;
130
+ border-color: var(--primary-color);
131
+ }
132
+
133
+ .option.correct {
134
+ background-color: #d4edda;
135
+ border-color: var(--success-color);
136
+ }
137
+
138
+ .option.incorrect {
139
+ background-color: #f8d7da;
140
+ border-color: var(--danger-color);
141
+ }
142
+
143
+ .option input {
144
+ margin-right: 10px;
145
+ cursor: pointer;
146
+ }
147
+
148
+ .option-label {
149
+ font-weight: 500;
150
+ flex-grow: 1;
151
+ }
152
+
153
+ .navigation {
154
+ display: flex;
155
+ justify-content: space-between;
156
+ margin-top: 2rem;
157
+ }
158
+
159
+ .btn {
160
+ padding: 12px 24px;
161
+ border: none;
162
+ border-radius: 6px;
163
+ cursor: pointer;
164
+ font-weight: 600;
165
+ transition: all 0.3s ease;
166
+ display: inline-flex;
167
+ align-items: center;
168
+ justify-content: center;
169
+ }
170
+
171
+ .btn-primary {
172
+ background-color: var(--primary-color);
173
+ color: white;
174
+ }
175
+
176
+ .btn-primary:hover {
177
+ background-color: var(--dark-color);
178
+ transform: translateY(-2px);
179
+ }
180
+
181
+ .btn-secondary {
182
+ background-color: #6c757d;
183
+ color: white;
184
+ }
185
+
186
+ .btn-secondary:hover {
187
+ background-color: #5a6268;
188
+ transform: translateY(-2px);
189
+ }
190
+
191
+ .btn:disabled {
192
+ opacity: 0.5;
193
+ cursor: not-allowed;
194
+ transform: none !important;
195
+ }
196
+
197
+ .result-container {
198
+ display: none;
199
+ background-color: white;
200
+ border-radius: 8px;
201
+ padding: 30px;
202
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
203
+ text-align: center;
204
+ }
205
+
206
+ .result-icon {
207
+ font-size: 5rem;
208
+ margin-bottom: 20px;
209
+ }
210
+
211
+ .excellent {
212
+ color: var(--success-color);
213
+ }
214
+
215
+ .good {
216
+ color: var(--primary-color);
217
+ }
218
+
219
+ .average {
220
+ color: var(--warning-color);
221
+ }
222
+
223
+ .poor {
224
+ color: var(--danger-color);
225
+ }
226
+
227
+ h2 {
228
+ margin-bottom: 20px;
229
+ color: var(--primary-color);
230
+ }
231
+
232
+ .score {
233
+ font-size: 3rem;
234
+ font-weight: bold;
235
+ margin-bottom: 20px;
236
+ }
237
+
238
+ .assessment {
239
+ font-size: 1.2rem;
240
+ margin-bottom: 25px;
241
+ max-width: 600px;
242
+ margin-left: auto;
243
+ margin-right: auto;
244
+ }
245
+
246
+ .restart-btn {
247
+ background-color: var(--primary-color);
248
+ color: white;
249
+ padding: 12px 30px;
250
+ border-radius: 6px;
251
+ border: none;
252
+ font-weight: 600;
253
+ cursor: pointer;
254
+ transition: all 0.3s ease;
255
+ display: inline-flex;
256
+ align-items: center;
257
+ }
258
+
259
+ .restart-btn i {
260
+ margin-right: 8px;
261
+ }
262
+
263
+ .restart-btn:hover {
264
+ background-color: var(--dark-color);
265
+ transform: translateY(-2px);
266
+ }
267
+
268
+ .explanation {
269
+ background-color: #f8f9fa;
270
+ border-left: 4px solid var(--primary-color);
271
+ padding: 15px;
272
+ margin-top: 20px;
273
+ border-radius: 0 6px 6px 0;
274
+ display: none;
275
+ }
276
+
277
+ .explanation-title {
278
+ font-weight: bold;
279
+ margin-bottom: 8px;
280
+ color: var(--primary-color);
281
+ }
282
+
283
+ .wrong-answers {
284
+ margin-top: 20px;
285
+ text-align: left;
286
+ max-width: 600px;
287
+ margin-left: auto;
288
+ margin-right: auto;
289
+ }
290
+
291
+ .wrong-answers-title {
292
+ font-weight: bold;
293
+ margin-bottom: 10px;
294
+ color: var(--danger-color);
295
+ }
296
+
297
+ .wrong-answer-item {
298
+ margin-bottom: 8px;
299
+ padding: 8px;
300
+ background-color: #f8f9fa;
301
+ border-radius: 4px;
302
+ }
303
+
304
+ @media (max-width: 768px) {
305
+ .container {
306
+ padding: 10px;
307
+ }
308
+
309
+ header h1 {
310
+ font-size: 2rem;
311
+ }
312
+
313
+ .quiz-container, .result-container {
314
+ padding: 20px;
315
+ }
316
+
317
+ .question {
318
+ font-size: 1.1rem;
319
+ }
320
+ }
321
+ </style>
322
+ </head>
323
+ <body>
324
+ <div class="container">
325
+ <header>
326
+ <div class="python-icon">
327
+ <i class="fab fa-python"></i>
328
+ </div>
329
+ <h1>Python Knowledge Test</h1>
330
+ <p>Test your Python programming skills with this 20-question quiz</p>
331
+ </header>
332
+
333
+ <div class="quiz-container" id="quiz">
334
+ <div class="question-counter">
335
+ <span>Question <span id="current-question">1</span> of 20</span>
336
+ <div class="progress-bar">
337
+ <div class="progress" id="progress"></div>
338
+ </div>
339
+ </div>
340
+
341
+ <div class="question" id="question"></div>
342
+
343
+ <div class="options" id="options"></div>
344
+
345
+ <div class="explanation" id="explanation">
346
+ <div class="explanation-title">
347
+ <i class="fas fa-info-circle"></i> Explanation
348
+ </div>
349
+ <div id="explanation-text"></div>
350
+ </div>
351
+
352
+ <div class="navigation">
353
+ <button class="btn btn-secondary" id="prev-btn" disabled>
354
+ <i class="fas fa-arrow-left"></i> Previous
355
+ </button>
356
+ <button class="btn btn-primary" id="next-btn">
357
+ Next <i class="fas fa-arrow-right"></i>
358
+ </button>
359
+ <button class="btn btn-primary" id="submit-btn" style="display: none;">
360
+ Submit <i class="fas fa-paper-plane"></i>
361
+ </button>
362
+ </div>
363
+ </div>
364
+
365
+ <div class="result-container" id="result-container">
366
+ <div class="result-icon" id="result-icon">
367
+ <i class="fas fa-trophy"></i>
368
+ </div>
369
+ <h2>Your Results</h2>
370
+ <div class="score" id="score"></div>
371
+ <div class="assessment" id="assessment"></div>
372
+
373
+ <div class="wrong-answers" id="wrong-answers">
374
+ <div class="wrong-answers-title">
375
+ <i class="fas fa-times-circle"></i> Incorrect Answers
376
+ </div>
377
+ <div id="wrong-answers-list"></div>
378
+ </div>
379
+
380
+ <button class="restart-btn" id="restart-btn">
381
+ <i class="fas fa-redo"></i> Take Again
382
+ </button>
383
+ </div>
384
+ </div>
385
+
386
+ <script>
387
+ // Questions array with options, correct answer, and explanations
388
+ const questions = [
389
+ {
390
+ question: "Which of the following is the correct way to declare a variable in Python?",
391
+ options: [
392
+ "var name = 'John'",
393
+ "name := 'John'",
394
+ "name = 'John'",
395
+ "let name = 'John'"
396
+ ],
397
+ correct: 2,
398
+ explanation: "In Python, variables are declared by simply assigning a value to a name using the equals sign (=). The other syntax shown is used in other languages like JavaScript or more recent Python versions for different purposes."
399
+ },
400
+ {
401
+ question: "What does the 'range()' function return in Python 3?",
402
+ options: [
403
+ "A list of numbers",
404
+ "A tuple of numbers",
405
+ "A range object",
406
+ "A set of numbers"
407
+ ],
408
+ correct: 2,
409
+ explanation: "In Python 3, range() returns an immutable sequence type (range object), not a list. This is more memory efficient as it generates numbers on demand rather than storing them all in memory."
410
+ },
411
+ {
412
+ question: "Which of these collection types in Python is immutable?",
413
+ options: [
414
+ "List",
415
+ "Dictionary",
416
+ "Set",
417
+ "Tuple"
418
+ ],
419
+ correct: 3,
420
+ explanation: "Tuples are immutable in Python, meaning they cannot be changed after creation. Lists, dictionaries, and sets are all mutable types."
421
+ },
422
+ {
423
+ question: "What is the output of '3 * 'ab' + 'ba' in Python?",
424
+ options: [
425
+ "'abababba'",
426
+ "'3abba'",
427
+ "'abababa'",
428
+ "Error"
429
+ ],
430
+ correct: 0,
431
+ explanation: "In Python, multiplying a string by an integer n concatenates the string with itself n times. So 3 * 'ab' becomes 'ababab', then adding 'ba' gives 'abababba'."
432
+ },
433
+ {
434
+ question: "What is the purpose of the '__init__' method in Python classes?",
435
+ options: [
436
+ "To destroy an object",
437
+ "To initialize the object's attributes",
438
+ "To create a new class",
439
+ "To import modules"
440
+ ],
441
+ correct: 1,
442
+ explanation: "The __init__ method is the constructor in Python classes. It's automatically called when an object is created and is used to initialize the object's state (attributes)."
443
+ },
444
+ {
445
+ question: "Which statement is used for exception handling in Python?",
446
+ options: [
447
+ "try-catch",
448
+ "try-except",
449
+ "try-exception",
450
+ "try-handle"
451
+ ],
452
+ correct: 1,
453
+ explanation: "Python uses try-except blocks for exception handling, unlike some other languages that use try-catch. The except block captures and handles exceptions that occur in the try block."
454
+ },
455
+ {
456
+ question: "What is the output of 'bool('False')' in Python?",
457
+ options: [
458
+ "False",
459
+ "True",
460
+ "Error",
461
+ "None"
462
+ ],
463
+ correct: 1,
464
+ explanation: "The bool() function converts values to boolean. Any non-empty string evaluates to True in Python, even if the string is 'False'. Only empty strings evaluate to False."
465
+ },
466
+ {
467
+ question: "Which method would you use to remove an item from a list and return it?",
468
+ options: [
469
+ "remove()",
470
+ "delete()",
471
+ "pop()",
472
+ "discard()"
473
+ ],
474
+ correct: 2,
475
+ explanation: "The pop() method removes and returns an item at the given index (or the last item if no index is specified). remove() deletes the first matching value, delete is a keyword, and discard() is a set method."
476
+ },
477
+ {
478
+ question: "What does the 'pass' statement do in Python?",
479
+ options: [
480
+ "Throws an error",
481
+ "Exits the program",
482
+ "Does nothing, acts as a placeholder",
483
+ "Continues to the next iteration in a loop"
484
+ ],
485
+ correct: 2,
486
+ explanation: "The pass statement is a null operation in Python - it does nothing. It's used when syntax requires a statement but no action is needed, often as a placeholder in empty functions, classes, or conditionals."
487
+ },
488
+ {
489
+ question: "How do you open a file for both reading and writing in Python?",
490
+ options: [
491
+ "open('file.txt', 'r')",
492
+ "open('file.txt', 'w')",
493
+ "open('file.txt', 'rw')",
494
+ "open('file.txt', 'r+')"
495
+ ],
496
+ correct: 3,
497
+ explanation: "The 'r+' mode opens a file for both reading and writing. 'r' is read-only, 'w' is write-only (overwrites file), and 'rw' is not a valid mode."
498
+ },
499
+ {
500
+ question: "What is the output of '[n**2 for n in range(5)]'?",
501
+ options: [
502
+ "[0, 1, 4, 9, 16]",
503
+ "[1, 2, 3, 4, 5]",
504
+ "[0, 1, 4, 9, 16, 25]",
505
+ "[1, 4, 9, 16, 25]"
506
+ ],
507
+ correct: 0,
508
+ explanation: "This is a list comprehension that squares each number in range(5), which produces numbers 0 to 4. The result is [0, 1, 4, 9, 16]."
509
+ },
510
+ {
511
+ question: "Which decorator is commonly used to define a method as a class method?",
512
+ options: [
513
+ "@staticmethod",
514
+ "@classmethod",
515
+ "@method",
516
+ "@property"
517
+ ],
518
+ correct: 1,
519
+ explanation: "The @classmethod decorator is used to define a method as a class method. It receives the class as the first argument (cls) rather than the instance (self)."
520
+ },
521
+ {
522
+ question: "What does the 'yield' keyword do in Python?",
523
+ options: [
524
+ "Returns a value from a function",
525
+ "Pauses function execution and returns a value",
526
+ "Terminates a function",
527
+ "Raises an exception"
528
+ ],
529
+ correct: 1,
530
+ explanation: "The yield keyword pauses function execution and returns a value to the caller, but retains enough state to resume where it left off. Functions containing yield are generator functions."
531
+ },
532
+ {
533
+ question: "How do you create a virtual environment in Python?",
534
+ options: [
535
+ "python -m venv myenv",
536
+ "python create virtualenv myenv",
537
+ "python -m virtualenv create myenv",
538
+ "python environment myenv"
539
+ ],
540
+ correct: 0,
541
+ explanation: "The standard way to create a virtual environment in Python is using 'python -m venv myenv'. This creates a new virtual environment in the 'myenv' directory."
542
+ },
543
+ {
544
+ question: "What is the purpose of the '__name__' variable in Python?",
545
+ options: [
546
+ "Stores the name of the current user",
547
+ "Holds the name of the current function",
548
+ "Contains the name of the module being executed",
549
+ "Is always '__main__'"
550
+ ],
551
+ correct: 2,
552
+ explanation: "The __name__ variable holds the name of the current module. When a module is run directly (not imported), __name__ is set to '__main__', which is a common pattern for code that should only run when the script is executed directly."
553
+ },
554
+ {
555
+ question: "Which of these is NOT a valid dictionary key in Python?",
556
+ options: [
557
+ "Integer",
558
+ "String",
559
+ "Tuple",
560
+ "List"
561
+ ],
562
+ correct: 3,
563
+ explanation: "In Python, dictionary keys must be immutable types. Lists are mutable and cannot be used as dictionary keys. Integers, strings, and tuples (if they contain only immutable elements) can be dictionary keys."
564
+ },
565
+ {
566
+ question: "What does the '//' operator do in Python?",
567
+ options: [
568
+ "Performs integer (floor) division",
569
+ "Is used for comments",
570
+ "Performs floating point division",
571
+ "Is the exponentiation operator"
572
+ ],
573
+ correct: 0,
574
+ explanation: "The // operator performs floor division, returning the largest integer less than or equal to the division result. For example, 5 // 2 returns 2, not 2.5."
575
+ },
576
+ {
577
+ question: "How do you check if an object is an instance of a particular class?",
578
+ options: [
579
+ "isinstance()",
580
+ "type()",
581
+ "classof()",
582
+ "Both isinstance() and type()"
583
+ ],
584
+ correct: 0,
585
+ explanation: "The isinstance() function checks if an object is an instance of a class or its subclasses, which is the preferred way to check types in Python. type() returns the exact type but doesn't account for inheritance."
586
+ },
587
+ {
588
+ question: "What is the output of 'print('Hello, World!'[::-1])'?",
589
+ options: [
590
+ "'Hello, World!'",
591
+ "'!dlroW ,olleH'",
592
+ "Error",
593
+ "'Hello, World!' printed multiple times"
594
+ ],
595
+ correct: 1,
596
+ explanation: "The [::-1] slicing creates a reversed copy of the string by stepping backward through the string. So 'Hello, World!' reversed is '!dlroW ,olleH'."
597
+ },
598
+ {
599
+ question: "Which module would you use for working with dates and times in Python?",
600
+ options: [
601
+ "datetime",
602
+ "time",
603
+ "cal",
604
+ "All of the above"
605
+ ],
606
+ correct: 0,
607
+ explanation: "The datetime module is the primary module for working with dates and times in Python. While the time module exists, it's lower-level, and there is no standard 'cal' module."
608
+ }
609
+ ];
610
+
611
+ // Quiz state
612
+ let currentQuestion = 0;
613
+ let score = 0;
614
+ let selectedOption = null;
615
+ let userAnswers = Array(questions.length).fill(null);
616
+
617
+ // DOM elements
618
+ const quizContainer = document.getElementById('quiz');
619
+ const resultContainer = document.getElementById('result-container');
620
+ const questionElement = document.getElementById('question');
621
+ const optionsElement = document.getElementById('options');
622
+ const currentQuestionElement = document.getElementById('current-question');
623
+ const progressElement = document.getElementById('progress');
624
+ const prevBtn = document.getElementById('prev-btn');
625
+ const nextBtn = document.getElementById('next-btn');
626
+ const submitBtn = document.getElementById('submit-btn');
627
+ const explanationElement = document.getElementById('explanation');
628
+ const explanationTextElement = document.getElementById('explanation-text');
629
+ const scoreElement = document.getElementById('score');
630
+ const assessmentElement = document.getElementById('assessment');
631
+ const resultIconElement = document.getElementById('result-icon');
632
+ const restartBtn = document.getElementById('restart-btn');
633
+ const wrongAnswersList = document.getElementById('wrong-answers-list');
634
+
635
+ // Initialize the quiz
636
+ function initQuiz() {
637
+ showQuestion();
638
+ updateNavigationButtons();
639
+ }
640
+
641
+ // Display the current question
642
+ function showQuestion() {
643
+ const question = questions[currentQuestion];
644
+ questionElement.textContent = question.question;
645
+ optionsElement.innerHTML = '';
646
+
647
+ currentQuestionElement.textContent = currentQuestion + 1;
648
+ progressElement.style.width = `${((currentQuestion + 1) / questions.length) * 100}%`;
649
+
650
+ // Create options
651
+ question.options.forEach((option, index) => {
652
+ const optionElement = document.createElement('div');
653
+ optionElement.className = 'option';
654
+ if (userAnswers[currentQuestion] === index) {
655
+ optionElement.classList.add('selected');
656
+ selectedOption = index;
657
+ }
658
+
659
+ const input = document.createElement('input');
660
+ input.type = 'radio';
661
+ input.name = 'option';
662
+ input.id = `option-${index}`;
663
+ input.value = index;
664
+ input.checked = userAnswers[currentQuestion] === index;
665
+ input.addEventListener('change', () => selectOption(index));
666
+
667
+ const label = document.createElement('label');
668
+ label.className = 'option-label';
669
+ label.htmlFor = `option-${index}`;
670
+ label.textContent = option;
671
+
672
+ optionElement.appendChild(input);
673
+ optionElement.appendChild(label);
674
+ optionsElement.appendChild(optionElement);
675
+ });
676
+
677
+ // Show explanation if this question was already answered
678
+ if (userAnswers[currentQuestion] !== null) {
679
+ showExplanation();
680
+ } else {
681
+ hideExplanation();
682
+ }
683
+ }
684
+
685
+ // Handle option selection
686
+ function selectOption(index) {
687
+ // Remove selected class from all options
688
+ document.querySelectorAll('.option').forEach(option => {
689
+ option.classList.remove('selected');
690
+ });
691
+
692
+ // Add selected class to clicked option
693
+ const selectedOptionElement = document.querySelector(`.option input[value="${index}"]`).parentNode;
694
+ selectedOptionElement.classList.add('selected');
695
+
696
+ selectedOption = index;
697
+ userAnswers[currentQuestion] = index;
698
+
699
+ // If it's the last question, show the submit button
700
+ if (currentQuestion === questions.length - 1 && userAnswers[currentQuestion] !== null) {
701
+ nextBtn.style.display = 'none';
702
+ submitBtn.style.display = 'inline-block';
703
+ } else {
704
+ nextBtn.style.display = 'inline-block';
705
+ submitBtn.style.display = 'none';
706
+ }
707
+
708
+ showExplanation();
709
+ }
710
+
711
+ // Show explanation for the current question
712
+ function showExplanation() {
713
+ if (userAnswers[currentQuestion] !== null) {
714
+ explanationTextElement.textContent = questions[currentQuestion].explanation;
715
+ explanationElement.style.display = 'block';
716
+ }
717
+ }
718
+
719
+ // Hide the explanation
720
+ function hideExplanation() {
721
+ explanationElement.style.display = 'none';
722
+ }
723
+
724
+ // Update navigation buttons state
725
+ function updateNavigationButtons() {
726
+ prevBtn.disabled = currentQuestion === 0;
727
+
728
+ // For the last question, show submit button if answered
729
+ if (currentQuestion === questions.length - 1) {
730
+ nextBtn.style.display = userAnswers[currentQuestion] === null ? 'inline-block' : 'none';
731
+ submitBtn.style.display = userAnswers[currentQuestion] !== null ? 'inline-block' : 'none';
732
+ } else {
733
+ nextBtn.style.display = 'inline-block';
734
+ submitBtn.style.display = 'none';
735
+ }
736
+ }
737
+
738
+ // Go to the next question
739
+ function nextQuestion() {
740
+ if (currentQuestion < questions.length - 1) {
741
+ currentQuestion++;
742
+ selectedOption = null;
743
+ showQuestion();
744
+ updateNavigationButtons();
745
+ }
746
+ }
747
+
748
+ // Go to the previous question
749
+ function prevQuestion() {
750
+ if (currentQuestion > 0) {
751
+ currentQuestion--;
752
+ selectedOption = userAnswers[currentQuestion];
753
+ showQuestion();
754
+ updateNavigationButtons();
755
+ }
756
+ }
757
+
758
+ // Submit the quiz and show results
759
+ function submitQuiz() {
760
+ // Calculate score and collect wrong answers
761
+ score = 0;
762
+ const wrongAnswers = [];
763
+
764
+ questions.forEach((question, index) => {
765
+ if (userAnswers[index] === question.correct) {
766
+ score++;
767
+ } else if (userAnswers[index] !== null) {
768
+ wrongAnswers.push({
769
+ questionNumber: index + 1,
770
+ question: question.question,
771
+ yourAnswer: question.options[userAnswers[index]],
772
+ correctAnswer: question.options[question.correct]
773
+ });
774
+ }
775
+ });
776
+
777
+ // Display results
778
+ quizContainer.style.display = 'none';
779
+ resultContainer.style.display = 'block';
780
+ scoreElement.textContent = `${score}/${questions.length}`;
781
+
782
+ // Calculate percentage
783
+ const percentage = (score / questions.length) * 100;
784
+
785
+ // Determine assessment
786
+ let assessment, iconClass, feedback;
787
+
788
+ if (percentage >= 90) {
789
+ assessment = "Python Expert!";
790
+ iconClass = "excellent";
791
+ feedback = "Outstanding! Your Python knowledge is comprehensive and detailed. You've demonstrated a deep understanding of Python concepts and syntax. Consider sharing your expertise with others!";
792
+ } else if (percentage >= 75) {
793
+ assessment = "Advanced Python User";
794
+ iconClass = "good";
795
+ feedback = "Great job! You have strong Python knowledge with just a few gaps. With a bit more practice, you'll master all the advanced concepts. Consider working on more complex projects to refine your skills.";
796
+ } else if (percentage >= 50) {
797
+ assessment = "Intermediate Python Programmer";
798
+ iconClass = "average";
799
+ feedback = "Good effort! You understand the basics and some intermediate concepts of Python. Focus on learning about functions, classes, and Python's standard library to improve your skills.";
800
+ } else {
801
+ assessment = "Python Beginner";
802
+ iconClass = "poor";
803
+ feedback = "You're just starting your Python journey! Focus on the fundamentals first - variables, data types, loops, and functions. Practice writing simple programs and gradually increase complexity.";
804
+ }
805
+
806
+ assessmentElement.textContent = feedback;
807
+ document.querySelector('#assessment').previousElementSibling.textContent = assessment;
808
+ document.querySelector('.result-icon i').className = `fas ${percentage >= 90 ? 'fa-trophy' : percentage >= 75 ? 'fa-award' : percentage >= 50 ? 'fa-star' : 'fa-book'}`;
809
+ resultIconElement.className = `result-icon ${iconClass}`;
810
+
811
+ // Display wrong answers if any
812
+ if (wrongAnswers.length > 0) {
813
+ wrongAnswersList.innerHTML = '';
814
+ wrongAnswers.forEach(item => {
815
+ const wrongAnswerElement = document.createElement('div');
816
+ wrongAnswerElement.className = 'wrong-answer-item';
817
+ wrongAnswerElement.innerHTML = `
818
+ <strong>Question ${item.questionNumber}:</strong> ${item.question}<br>
819
+ <span style="color: var(--danger-color);">Your answer: ${item.yourAnswer}</span><br>
820
+ <span style="color: var(--success-color);">Correct answer: ${item.correctAnswer}</span>
821
+ `;
822
+ wrongAnswersList.appendChild(wrongAnswerElement);
823
+ });
824
+ document.getElementById('wrong-answers').style.display = 'block';
825
+ } else {
826
+ document.getElementById('wrong-answers').style.display = 'none';
827
+ }
828
+ }
829
+
830
+ // Restart the quiz
831
+ function restartQuiz() {
832
+ currentQuestion = 0;
833
+ score = 0;
834
+ selectedOption = null;
835
+ userAnswers = Array(questions.length).fill(null);
836
+
837
+ quizContainer.style.display = 'block';
838
+ resultContainer.style.display = 'none';
839
+
840
+ showQuestion();
841
+ updateNavigationButtons();
842
+ }
843
+
844
+ // Event listeners
845
+ nextBtn.addEventListener('click', nextQuestion);
846
+ prevBtn.addEventListener('click', prevQuestion);
847
+ submitBtn.addEventListener('click', submitQuiz);
848
+ restartBtn.addEventListener('click', restartQuiz);
849
+
850
+ // Initialize the quiz when the page loads
851
+ window.addEventListener('DOMContentLoaded', initQuiz);
852
+ </script>
853
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: absolute; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">This website has been generated by <a href="https://enzostvs-deepsite.hf.space" style="color: #fff;" target="_blank" >DeepSite</a> <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;"></p></body>
854
+ </html>