Embercode
✕
References and MemoryQuick quiz

Layout and object size

8 questions. Covers Object sizes and __slots__ in Python.

Questions 1 to 5 of 8

  1. 1. What does this print? ``python rows, cols = 3, 5 flat = [0] * (rows * cols) for r in range(rows): for c in range(cols): flat[r * cols + c] = r * 10 + c print(flat[2 * cols + 1]) ``
  2. 2. What does this print? ``python g = [[0] * 2, [0] * 4, [0] * 1] total = 0 for r in range(len(g)): total += len(g[r]) print(len(g), total) ``
  3. 3. What does this print? ``python rows, cols = 3, 5 flat = [0] * (rows * cols) for r in range(rows): for c in range(cols): flat[r * cols + c] = r * 10 + c r, c = 0, 1 print(flat[c * cols + r]) ``
  4. 4. In row-major order, a grid with cols columns stores the cell at row r and column c at index r * ___ + c. Fill in the blank.

    Type your answer.

  5. 5. Which Python operator gives the column of a flat index? Write it as index ___ cols, with the symbol only.

    Type your answer.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.