eaglelandsonce commited on
Commit
c3ae09d
·
verified ·
1 Parent(s): 6f3693c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +100 -178
index.html CHANGED
@@ -1,86 +1,34 @@
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>Week 1 Python Questions</title>
7
  <style>
8
- body {
9
- font-family: Arial, sans-serif;
10
- display: flex;
11
- flex-direction: column;
12
- align-items: center;
13
- background-color: #f0f0f0;
14
- margin: 0;
15
- }
16
- h1 { color: #0078D4; }
17
- #game-board {
18
- display: grid;
19
- grid-template-columns: repeat(5, 1fr);
20
- grid-auto-rows: 100px;
21
- gap: 2px;
22
- margin: 20px 0;
23
- background-color: #000;
24
- border: 4px solid #000;
25
- width: 90%;
26
- }
27
- .category {
28
- background-color: #005a9e;
29
- color: #fff;
30
- font-weight: bold;
31
- display: flex;
32
- justify-content: center;
33
- align-items: center;
34
- text-align: center;
35
- font-size: 18px;
36
- border: 1px solid #000;
37
- }
38
- .card {
39
- background-color: #0078D4;
40
- color: #fff;
41
- display: flex;
42
- justify-content: center;
43
- align-items: center;
44
- font-size: 16px;
45
- font-weight: bold;
46
- cursor: pointer;
47
- border: 1px solid #000;
48
- text-align: center;
49
- transition: background-color 0.3s;
50
- }
51
- .card:hover { background-color: #005a9e; }
52
- .card.disabled { background-color: #cccccc; cursor: default; }
53
- #question-display { width: 80%; text-align: center; margin-bottom: 20px; }
54
- #score { font-size: 24px; font-weight: bold; color: #0078D4; }
55
- .answer-container {
56
- display: flex; flex-wrap: wrap; justify-content: center; margin-top: 20px;
57
- }
58
- .answer-btn {
59
- margin: 5px; padding: 10px 15px; font-size: 18px; cursor: pointer; text-align: center;
60
- border: 2px solid #005a9e; border-radius: 5px; background-color: #0078D4; color: #fff;
61
- font-weight: bold; transition: background-color 0.3s, color 0.3s;
62
- }
63
- .answer-btn:hover { background-color: #005a9e; color: #f0f0f0; }
64
- .answer-btn.disabled { background-color: #cccccc; color: #666; cursor: not-allowed; }
65
- .feedback { margin-top: 10px; font-size: 18px; font-weight: bold; }
66
  </style>
67
  </head>
68
  <body>
69
  <h1>Week 1 Python Questions</h1>
70
- <p>
71
- <strong>Learn More:</strong>
72
- <a href="https://chatgpt.com/g/g-67d5c827fc7c81919c5397d969d78a90-python-buddy-and-joke-teller" target="_blank">
73
- Python Buddy and Joke Teller
74
- </a>
75
- </p>
76
  <div id="game-board">
77
- <!-- Category Headers -->
78
  <div class="category">Variables & Data Structures</div>
79
  <div class="category">Operators</div>
80
  <div class="category">Conditional Statements</div>
81
  <div class="category">Looping Statements</div>
82
  <div class="category">Functions</div>
83
- <!-- Question Cards will be created dynamically below the headers -->
84
  </div>
85
  <div id="question-display"></div>
86
  <div id="score">Score: 0</div>
@@ -94,130 +42,116 @@
94
  "Functions"
95
  ];
96
 
 
97
  const questions = [
98
  // Variables & Data Structures
99
  [
100
  {
101
- q: "Which of the following is true regarding variables in Python?",
102
  a: [
103
- "Values assigned to variables can be modified",
104
- "Variables can store data structures such as arrays and dictionaries",
105
- "Variables can only store integer and floats",
106
- "Variables can store integer, floats, strings and booleans"
107
  ],
108
- correct: 3
109
  },
110
  {
111
- q: "Which of the following data structures in Python are mutable (can be modified after creation)?",
112
- a: ["Only List", "Tuple and Dictionary", "List and Tuple", "List and Dictionary"],
113
- correct: 3
114
  },
115
  {
116
- q: "Which of the following will retrieve the two middle elements from the list?\n\nmy_list = [1, \"two\", 3.5, \"four\", 5, 6.0, \"seven\", 8.2]",
117
- a: ["my_list[3:5]", "my_list[4:6]", "my_list[-5:-3]", "my_list[-4:-6]"],
118
  correct: 0
119
  }
120
  ],
121
  // Operators
122
  [
123
  {
124
- q: "Which of the following combinations accurately matches mathematical symbols with their respective operations?",
125
- a: [
126
- "+ for addition, - for subtraction",
127
- "* for exponentiation, / for modulus",
128
- "% for multiplication, ** for division",
129
- "** for multiplication, % for subtraction"
130
- ],
131
  correct: 0
132
  },
133
  {
134
- q: "What is the output of the expression 2 + 3 * 4 in Python?",
135
- a: ["14", "20", "24", "18"],
136
  correct: 0
137
  },
138
  {
139
- q: "Which operator is used for exponentiation in Python?",
140
- a: ["^", "**", "pow", "exp"],
141
- correct: 1
142
  }
143
  ],
144
  // Conditional Statements
145
  [
146
  {
147
- q: "Which statement accurately describes the behavior of the 'elif' construct in Python?",
148
  a: [
149
- "\"elif\" is used to define a block of code to be executed if the preceding \"if\" or \"elif\" condition(s) evaluate to False.",
150
- "\"elif\" is mandatory and must be included after every \"if\" statement.",
151
- "\"elif\" is used only when there are multiple conditions and no \"else\" block is present.",
152
- "\"elif\" is equivalent to \"else if\" and can be used interchangeably with the \"else\" statement."
153
  ],
154
  correct: 0
155
  },
156
  {
157
- q: "What keyword is used in Python to start an alternative block if none of the preceding conditions are true?",
158
- a: ["else", "otherwise", "default", "finally"],
159
  correct: 0
160
  },
161
  {
162
- q: "Consider the following code snippet:\n\nif x > 10:\n console.log(\"Greater\")\nelif x == 10:\n console.log(\"Equal\")\nelse:\n console.log(\"Less\")\n\nWhich block is executed when x is 10?",
163
- a: ["if block", "elif block", "else block", "None of the above"],
164
- correct: 1
165
  }
166
  ],
167
  // Looping Statements
168
  [
169
  {
170
- q: "Which of the following statements is true regarding loops in Python?",
171
  a: [
172
- "The \"for\" loop requires a condition to be evaluated before execution.",
173
- "The \"for\" loop iterates through a sequence, executing on each element.",
174
- "The \"while\" loop iterates through a sequence, executing on each element.",
175
- "The \"while\" loop does not require a condition to be evaluated."
176
  ],
177
- correct: 1
178
  },
179
  {
180
- q: "What is the output of the following code?\n\nfor i in range(1, 4):\n document.write(i + ' ');",
181
- a: ["1 2 3", "1 2 3 4", "0 1 2", "1 3"],
182
  correct: 0
183
  },
184
  {
185
- q: "Which loop structure is best suited for iterating over elements in a list when the number of iterations is known?",
186
- a: ["while loop", "for loop", "do-while loop", "if-else loop"],
187
- correct: 1
188
  }
189
  ],
190
  // Functions
191
  [
192
  {
193
- q: "What is the primary purpose of functions in Python?",
194
  a: [
195
- "To execute a specific task only once in a program.",
196
- "To break code into modular chunks for reusability and organization.",
197
- "To combine multiple variables into a single variable.",
198
- "To declare built-in variables that are predefined."
199
  ],
200
- correct: 1
201
  },
202
  {
203
- q: "How do you define a user-defined function in Python?",
204
- a: [
205
- "function functionName(parameters):",
206
- "def functionName(parameters):",
207
- "func functionName(parameters):",
208
- "define functionName(parameters):"
209
- ],
210
- correct: 1
211
  },
212
  {
213
- q: "Which of the following statements about the return statement in Python is false?",
214
  a: [
215
- "A function can have multiple return statements.",
216
- "A function can return multiple values in a single return statement.",
217
- "The return statement returns a value computed by the function.",
218
- "A function must always include a return statement."
219
  ],
220
- correct: 3
221
  }
222
  ]
223
  ];
@@ -229,11 +163,9 @@
229
  const questionDisplay = document.getElementById("question-display");
230
  const scoreDisplay = document.getElementById("score");
231
 
232
- // Precompute an even distribution of correct positions (0,1,2) over 15 cards.
233
  const correctPositions = (() => {
234
- const arr = [];
235
- for (let i = 0; i < totalCards; i++) arr.push(i % 3); // five 0s, five 1s, five 2s
236
- // Shuffle
237
  for (let i = arr.length - 1; i > 0; i--) {
238
  const j = Math.floor(Math.random() * (i + 1));
239
  [arr[i], arr[j]] = [arr[j], arr[i]];
@@ -241,12 +173,11 @@
241
  return arr;
242
  })();
243
 
244
- // Persist per-question generated choices and correct index.
245
- const questionMeta = new Map(); // key: "c-d" -> { choices: string[3], correctIndex: 0|1|2 }
246
 
247
- function getQuestionIndex(category, difficulty) {
248
- // Stable mapping 0..14: group by category columns, each with 3 rows
249
- return category * 3 + difficulty;
250
  }
251
 
252
  function createBoard() {
@@ -254,48 +185,42 @@
254
  for (let col = 0; col < 5; col++) {
255
  const card = document.createElement("div");
256
  card.className = "card";
257
- card.textContent = "$" + ((row + 1) * 100);
258
  card.onclick = () => showQuestion(col, row, card);
259
  gameBoard.appendChild(card);
260
  }
261
  }
262
  }
263
 
264
- function prepareThreeChoices(category, difficulty) {
265
  const key = `${category}-${difficulty}`;
266
  if (questionMeta.has(key)) return questionMeta.get(key);
267
 
268
  const q = questions[category][difficulty];
269
- const all = q.a;
270
- const correctIdxInAll = q.correct;
271
- const correctText = all[correctIdxInAll];
272
 
273
- // Collect indices of wrong answers
274
- const wrongIdxs = all.map((_, i) => i).filter(i => i !== correctIdxInAll);
275
-
276
- // Pick 2 wrong answers at random
277
- for (let i = wrongIdxs.length - 1; i > 0; i--) {
278
  const j = Math.floor(Math.random() * (i + 1));
279
- [wrongIdxs[i], wrongIdxs[j]] = [wrongIdxs[j], wrongIdxs[i]];
280
  }
281
- const chosenWrongs = wrongIdxs.slice(0, 2).map(i => all[i]);
282
-
283
- // Place correct answer at preassigned position for this question
284
- const pos = correctPositions[getQuestionIndex(category, difficulty)];
285
- const slots = [null, null, null];
286
- slots[pos] = correctText;
287
 
288
- // Fill remaining slots with the two wrong answers (random order)
289
- const shuffledWrongs = [...chosenWrongs];
290
- if (Math.random() < 0.5) shuffledWrongs.reverse();
291
- let wi = 0;
292
- for (let s = 0; s < 3; s++) {
293
- if (slots[s] === null) {
294
- slots[s] = shuffledWrongs[wi++];
295
- }
296
  }
297
 
298
- const meta = { choices: slots, correctIndex: pos };
 
 
 
299
  questionMeta.set(key, meta);
300
  return meta;
301
  }
@@ -304,17 +229,17 @@
304
  if (cardElement.classList.contains("disabled")) return;
305
 
306
  const q = questions[category][difficulty];
307
- const { choices, correctIndex } = prepareThreeChoices(category, difficulty);
308
 
309
  const answerHtml = choices
310
- .map((answer, index) =>
311
- `<button class="answer-btn" onclick="checkAnswer(${category}, ${difficulty}, ${index})">${answer}</button>`
312
  )
313
  .join("");
314
 
315
  questionDisplay.innerHTML = `
316
  <h2>${categories[category]} for $${(difficulty + 1) * 100}</h2>
317
- <p>${q.q}</p>
318
  <div class="answer-container">${answerHtml}</div>`;
319
 
320
  cardElement.classList.add("disabled");
@@ -325,22 +250,21 @@
325
  function checkAnswer(category, difficulty, selectedIndex) {
326
  const key = `${category}-${difficulty}`;
327
  const meta = questionMeta.get(key);
328
- const q = questions[category][difficulty];
329
- const correctText = meta.choices[meta.correctIndex];
330
  const isCorrect = selectedIndex === meta.correctIndex;
331
  const value = (difficulty + 1) * 100;
332
 
333
- document.querySelectorAll(".answer-btn").forEach((btn) => {
334
  btn.disabled = true;
335
  btn.classList.add("disabled");
336
  });
337
 
338
  if (isCorrect) {
339
  score += value;
340
- questionDisplay.innerHTML += `<p class="feedback" style="color: green;">Correct! You earned $${value}.</p>`;
341
  } else {
342
  score -= value;
343
- questionDisplay.innerHTML += `<p class="feedback" style="color: red;">Wrong! You lost $${value}. The correct answer was: ${correctText}</p>`;
 
344
  }
345
 
346
  scoreDisplay.textContent = "Score: " + score;
@@ -351,9 +275,7 @@
351
  questionDisplay.innerHTML = `<h2>Game Over!</h2><p>Your final score is $${score}.</p>`;
352
  }
353
 
354
- // Expose functions needed by inline onclick handlers
355
  window.checkAnswer = checkAnswer;
356
-
357
  createBoard();
358
  </script>
359
  </body>
 
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>Week 1 Python Questions</title>
7
  <style>
8
+ body{font-family:Arial,sans-serif;display:flex;flex-direction:column;align-items:center;background:#f0f0f0;margin:0}
9
+ h1{color:#0078D4}
10
+ #game-board{display:grid;grid-template-columns:repeat(5,1fr);grid-auto-rows:100px;gap:2px;margin:20px 0;background:#000;border:4px solid #000;width:90%}
11
+ .category{background:#005a9e;color:#fff;font-weight:bold;display:flex;justify-content:center;align-items:center;text-align:center;font-size:18px;border:1px solid #000}
12
+ .card{background:#0078D4;color:#fff;display:flex;justify-content:center;align-items:center;font-size:16px;font-weight:bold;cursor:pointer;border:1px solid #000;text-align:center;transition:background-color .3s}
13
+ .card:hover{background:#005a9e}
14
+ .card.disabled{background:#ccc;cursor:default}
15
+ #question-display{width:80%;text-align:center;margin-bottom:20px}
16
+ #score{font-size:24px;font-weight:bold;color:#0078D4}
17
+ .answer-container{display:flex;flex-wrap:wrap;justify-content:center;margin-top:20px}
18
+ .answer-btn{margin:5px;padding:10px 15px;font-size:18px;cursor:pointer;text-align:center;border:2px solid #005a9e;border-radius:5px;background:#0078D4;color:#fff;font-weight:bold;transition:background-color .3s,color .3s}
19
+ .answer-btn:hover{background:#005a9e;color:#f0f0f0}
20
+ .answer-btn.disabled{background:#ccc;color:#666;cursor:not-allowed}
21
+ .feedback{margin-top:10px;font-size:18px;font-weight:bold}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  </style>
23
  </head>
24
  <body>
25
  <h1>Week 1 Python Questions</h1>
 
 
 
 
 
 
26
  <div id="game-board">
 
27
  <div class="category">Variables & Data Structures</div>
28
  <div class="category">Operators</div>
29
  <div class="category">Conditional Statements</div>
30
  <div class="category">Looping Statements</div>
31
  <div class="category">Functions</div>
 
32
  </div>
33
  <div id="question-display"></div>
34
  <div id="score">Score: 0</div>
 
42
  "Functions"
43
  ];
44
 
45
+ // ✅ Cleaned questions: Python-correct code, unique correct answers, 3 options each
46
  const questions = [
47
  // Variables & Data Structures
48
  [
49
  {
50
+ q: "Which statement best describes Python variables?",
51
  a: [
52
+ "They are names bound to objects; names can be rebound",
53
+ "They must be declared with a type keyword before use",
54
+ "They can only reference numbers and strings"
 
55
  ],
56
+ correct: 0
57
  },
58
  {
59
+ q: "Which Python data structures are mutable?",
60
+ a: ["List and Dictionary", "Tuple and String", "Set and Tuple"],
61
+ correct: 0
62
  },
63
  {
64
+ q: "Which slice returns ['four', 5] from my_list = [1, 'two', 3.5, 'four', 5, 6.0, 'seven', 8.2]?",
65
+ a: ["my_list[3:5]", "my_list[2:4]", "my_list[-4:-2]"],
66
  correct: 0
67
  }
68
  ],
69
  // Operators
70
  [
71
  {
72
+ q: "Which pairing correctly matches Python operators with operations?",
73
+ a: ["+ for addition, - for subtraction", "** for modulus, % for exponentiation", "% for division, / for multiplication"],
 
 
 
 
 
74
  correct: 0
75
  },
76
  {
77
+ q: "What is the result of 2 + 3 * 4 in Python?",
78
+ a: ["14", "20", "24"],
79
  correct: 0
80
  },
81
  {
82
+ q: "Which operator performs exponentiation in Python?",
83
+ a: ["**", "^", "exp()"],
84
+ correct: 0
85
  }
86
  ],
87
  // Conditional Statements
88
  [
89
  {
90
+ q: "What does 'elif' do in Python?",
91
  a: [
92
+ "Tests another condition if previous tests were False",
93
+ "Runs when the preceding 'if' was True",
94
+ "Is mandatory after every 'if'"
 
95
  ],
96
  correct: 0
97
  },
98
  {
99
+ q: "Which keyword begins the fallback block when no prior condition was True?",
100
+ a: ["else", "otherwise", "default"],
101
  correct: 0
102
  },
103
  {
104
+ q: "Given: if x > 10: print('Greater')\nelif x == 10: print('Equal')\nelse: print('Less')\nWhat prints when x == 10?",
105
+ a: ["Equal", "Greater", "Less"],
106
+ correct: 0
107
  }
108
  ],
109
  // Looping Statements
110
  [
111
  {
112
+ q: "Which is true of Python's 'for' loop?",
113
  a: [
114
+ "It iterates over items of an iterable",
115
+ "It repeats while a condition is True",
116
+ "It requires a manual counter only"
 
117
  ],
118
+ correct: 0
119
  },
120
  {
121
+ q: "What does this print?\nfor i in range(1, 4):\n print(i, end=' ')",
122
+ a: ["1 2 3 ", "0 1 2 ", "1 2 3 4 "],
123
  correct: 0
124
  },
125
  {
126
+ q: "Best loop for iterating a list when the number of passes is known?",
127
+ a: ["for loop", "while loop", "do-while loop"],
128
+ correct: 0
129
  }
130
  ],
131
  // Functions
132
  [
133
  {
134
+ q: "Primary purpose of functions in Python?",
135
  a: [
136
+ "Encapsulate reusable logic into named blocks",
137
+ "Declare compile-time constants",
138
+ "Only execute once per program"
 
139
  ],
140
+ correct: 0
141
  },
142
  {
143
+ q: "How do you define a function?",
144
+ a: ["def my_func(params):", "function my_func(params):", "define my_func(params):"],
145
+ correct: 0
 
 
 
 
 
146
  },
147
  {
148
+ q: "Which statement about 'return' is false?",
149
  a: [
150
+ "Every function must include a 'return' statement",
151
+ "A function can return multiple values",
152
+ "A function may have multiple 'return' paths"
 
153
  ],
154
+ correct: 0
155
  }
156
  ]
157
  ];
 
163
  const questionDisplay = document.getElementById("question-display");
164
  const scoreDisplay = document.getElementById("score");
165
 
166
+ // Even distribution of correct positions (0..2) across 15 questions
167
  const correctPositions = (() => {
168
+ const arr = Array.from({ length: totalCards }, (_, i) => i % 3); // five of each
 
 
169
  for (let i = arr.length - 1; i > 0; i--) {
170
  const j = Math.floor(Math.random() * (i + 1));
171
  [arr[i], arr[j]] = [arr[j], arr[i]];
 
173
  return arr;
174
  })();
175
 
176
+ // Memo for per-question permuted choices
177
+ const questionMeta = new Map(); // "c-d" -> { choices:[...3], correctIndex }
178
 
179
+ function qIndex(category, difficulty) {
180
+ return category * 3 + difficulty; // 0..14
 
181
  }
182
 
183
  function createBoard() {
 
185
  for (let col = 0; col < 5; col++) {
186
  const card = document.createElement("div");
187
  card.className = "card";
188
+ card.textContent = "$" + (row + 1) * 100;
189
  card.onclick = () => showQuestion(col, row, card);
190
  gameBoard.appendChild(card);
191
  }
192
  }
193
  }
194
 
195
+ function prepareChoices(category, difficulty) {
196
  const key = `${category}-${difficulty}`;
197
  if (questionMeta.has(key)) return questionMeta.get(key);
198
 
199
  const q = questions[category][difficulty];
200
+ const baseChoices = q.a.slice(); // already length 3
201
+ const origCorrect = q.correct; // index in baseChoices
 
202
 
203
+ // Start with a random permutation
204
+ const idxs = [0, 1, 2];
205
+ for (let i = idxs.length - 1; i > 0; i--) {
 
 
206
  const j = Math.floor(Math.random() * (i + 1));
207
+ [idxs[i], idxs[j]] = [idxs[j], idxs[i]];
208
  }
 
 
 
 
 
 
209
 
210
+ // Ensure the correct answer ends up at the prescribed position
211
+ const targetPos = correctPositions[qIndex(category, difficulty)];
212
+ const currentPosOfCorrect = idxs.indexOf(origCorrect);
213
+ if (currentPosOfCorrect !== targetPos) {
214
+ // swap positions
215
+ const swapIdx = idxs[targetPos];
216
+ idxs[targetPos] = origCorrect;
217
+ idxs[currentPosOfCorrect] = swapIdx;
218
  }
219
 
220
+ const choices = idxs.map(i => baseChoices[i]);
221
+ const correctIndex = targetPos;
222
+
223
+ const meta = { choices, correctIndex };
224
  questionMeta.set(key, meta);
225
  return meta;
226
  }
 
229
  if (cardElement.classList.contains("disabled")) return;
230
 
231
  const q = questions[category][difficulty];
232
+ const { choices } = prepareChoices(category, difficulty);
233
 
234
  const answerHtml = choices
235
+ .map((answer, idx) =>
236
+ `<button class="answer-btn" onclick="checkAnswer(${category}, ${difficulty}, ${idx})">${answer}</button>`
237
  )
238
  .join("");
239
 
240
  questionDisplay.innerHTML = `
241
  <h2>${categories[category]} for $${(difficulty + 1) * 100}</h2>
242
+ <pre style="white-space:pre-wrap;text-align:left;background:#fff;border:1px solid #ddd;padding:10px;border-radius:6px">${q.q}</pre>
243
  <div class="answer-container">${answerHtml}</div>`;
244
 
245
  cardElement.classList.add("disabled");
 
250
  function checkAnswer(category, difficulty, selectedIndex) {
251
  const key = `${category}-${difficulty}`;
252
  const meta = questionMeta.get(key);
 
 
253
  const isCorrect = selectedIndex === meta.correctIndex;
254
  const value = (difficulty + 1) * 100;
255
 
256
+ document.querySelectorAll(".answer-btn").forEach(btn => {
257
  btn.disabled = true;
258
  btn.classList.add("disabled");
259
  });
260
 
261
  if (isCorrect) {
262
  score += value;
263
+ questionDisplay.innerHTML += `<p class="feedback" style="color:green">Correct! You earned $${value}.</p>`;
264
  } else {
265
  score -= value;
266
+ const correctText = meta.choices[meta.correctIndex];
267
+ questionDisplay.innerHTML += `<p class="feedback" style="color:red">Wrong! You lost $${value}. Correct answer: ${correctText}</p>`;
268
  }
269
 
270
  scoreDisplay.textContent = "Score: " + score;
 
275
  questionDisplay.innerHTML = `<h2>Game Over!</h2><p>Your final score is $${score}.</p>`;
276
  }
277
 
 
278
  window.checkAnswer = checkAnswer;
 
279
  createBoard();
280
  </script>
281
  </body>