Embercode
✕
ArraysQuick quiz

Bounds debugging

6 questions. Covers Out-of-bounds debugging lab in Python.

Questions 1 to 5 of 6

  1. 1. Spot the bug. This program crashes. What is the cause? ``python grid = [[0] * 3 for _ in range(2)] for r in range(len(grid) + 1): for c in range(len(grid[r])): grid[r][c] = 1 print("filled") ``
  2. 2. What does this program print? ``python w = [5, 5, 7, 2] rises = 0 for i in range(len(w) - 1): if w[i + 1] > w[i]: rises += 1 print("Rises:", rises) ``
  3. 3. Spot the bug. The program is meant to print the third day, Wed, but it crashes with IndexError: list index out of range. What is the cause? ``python days = ["Mon", "Tue", "Wed"] day = 3 print(days[day]) ``
  4. 4. Which statement about the length of a list and a string is true?
  5. 5. Spot the bug. The program should print the last value, but it crashes with IndexError: list index out of range. What fixes it? ``python arr = [4, 8, 15, 16, 23] last = arr[len(arr)] print(last) ``

5 question(s) left on this page.