Programming Questions Manager

Create and manage programming questions for the interactive challenge.

Questions (2)

List Comprehension Bug
Python
Easy
Syntax

This code should create a list of squares for even numbers, but it has a bug:

numbers = [1, 2, 3, 4, 5, 6]
result = [x**2 for x in numbers if x % 2 = 0]
print(result)

Options:

A. Change x**2 to x*2
B. Change = to ==
C. Change % to //
D. Add parentheses around x % 2

Explanation: The bug is using = (assignment) instead of == (comparison) in the condition.

Function Scope Issue
JavaScript
Medium
Variables

This function should return the sum of an array, but it doesn't work:

function sumArray(arr) {
  for (let i = 0; i < arr.length; i++) {
    sum += arr[i];
  }
  return sum;
}

Options:

A. Initialize sum variable before the loop
B. Change let to var
C. Use arr.forEach instead
D. Add semicolon after return sum

Explanation: The variable "sum" is not declared. It should be initialized before the loop.