Hack4Hack

Daily Coding Quiz: Monday, 9 November 2026

All 10 coding questions with answers and explanations. 0 players took part.

  1. What is printed?

    Python · easy

    print("hack" * 2 + "!")
    1. hack2!
    2. hackhack!
    3. hack!hack!
    4. TypeError

    Answer: B. hackhack!

    Explanation: Multiplying a string by an integer repeats it; + then concatenates "!".

  2. Which layer turns a vector of scores into probabilities that add up to 1?

    AI & GenAI · easy

    1. ReLU
    2. Softmax
    3. Dropout
    4. Batch normalisation

    Answer: B. Softmax

    Explanation: softmax(zᵢ) = e^zᵢ / Σ e^zⱼ: every output is positive and they sum to 1, so it is used for multi-class outputs and next-token prediction.

  3. What is printed?

    Python · easy

    print([x * x for x in range(5) if x % 2 == 0])
    1. [0, 4, 16]
    2. [1, 9]
    3. [0, 1, 4, 9, 16]
    4. [4, 16]

    Answer: A. [0, 4, 16]

    Explanation: range(5) is 0–4; the even ones are 0, 2, 4, and their squares are 0, 4, 16.

  4. What is the shape of a 640 × 480 colour image loaded with OpenCV (cv2.imread)?

    Computer Vision · easy

    1. (640, 480, 3)
    2. (480, 640, 3)
    3. (3, 480, 640)
    4. (480, 640)

    Answer: B. (480, 640, 3)

    Explanation: NumPy arrays are (rows, columns, channels) = (height, width, 3). Also note OpenCV stores the channels as BGR, not RGB.

  5. What is printed?

    Python · medium

    print(sorted(["banana", "Apple", "cherry"]))
    1. ['Apple', 'banana', 'cherry']
    2. ['apple', 'banana', 'cherry']
    3. ['banana', 'cherry', 'Apple']
    4. ['cherry', 'banana', 'Apple']

    Answer: A. ['Apple', 'banana', 'cherry']

    Explanation: Strings sort by code point, and capital letters come before lowercase ones, so "Apple" is first here. Use key=str.lower to sort case-insensitively.

  6. What is printed?

    Python · medium

    x = 10
    def f():
        x = 20
        def g():
            nonlocal x
            x += 1
        g()
        return x
    print(f(), x)
    1. 21 10
    2. 21 21
    3. 11 10
    4. 20 10

    Answer: A. 21 10

    Explanation: nonlocal makes g change f’s x (20 → 21). The global x stays 10.

  7. What is printed?

    Python · medium

    def add(item, box=[]):
        box.append(item)
        return box
    
    add(1)
    print(add(2))
    1. [2]
    2. [1, 2]
    3. []
    4. An error

    Answer: B. [1, 2]

    Explanation: Default values are evaluated once, when the function is defined. Both calls share the same list. Use box=None and create the list inside.

  8. Your training and validation losses are both high and close together. What is the most useful next step?

    Machine Learning · hard

    1. Add dropout and more regularisation
    2. Collect more of the same data
    3. Increase model capacity or add better features: the model is underfitting
    4. Use early stopping sooner

    Answer: C. Increase model capacity or add better features: the model is underfitting

    Explanation: High bias: the model can’t even fit the training data. Regularisation and early stopping fight variance, and more data mostly helps when the model overfits.

  9. What is printed?

    Python · hard

    class Counter:
        count = 0
        def __init__(self):
            self.count += 1
    
    a, b = Counter(), Counter()
    print(Counter.count, a.count, b.count)
    1. 0 1 1
    2. 2 2 2
    3. 2 1 2
    4. 0 0 0

    Answer: A. 0 1 1

    Explanation: self.count += 1 reads the class attribute (0) but writes a new instance attribute. The class attribute is never changed. Write Counter.count += 1 to share it.

  10. What is printed?

    Python · hard

    def gen():
        x = yield 1
        yield x * 10
    
    g = gen()
    print(next(g), g.send(5))
    1. 1 50
    2. 1 10
    3. 1 None
    4. TypeError

    Answer: A. 1 50

    Explanation: next(g) runs to the first yield and gives 1. send(5) resumes the generator, making the paused yield expression evaluate to 5, so the next yield gives 50.

Play the next Daily Quiz at 4 PM IST