Embercode
✕
Linked ListsQuick quiz

Pointer bug hunt

9 questions. Covers Debugging lab: pointer bugs in Python lists.

Questions 1 to 5 of 9

  1. 1. What is the bug in this function? ``python def add_last_broken(head, v): cur = head while cur is not None: cur = cur.next cur.next = Node(v) ` Called on build(1, 2, 3), it raises AttributeError`.
  2. 2. Python raises which exception class when code reads or writes an attribute through a None value, such as cur.next when cur is None? Give the class name.

    Type your answer.

  3. 3. The code below runs in one program. What does it print, one value per line? ``python x1 = int("256") x2 = int("256") y1 = int("257") y2 = int("257") print(x1 is x2) print(y1 is y2) print(y1 == y2) ``
  4. 4. What is the bug in this function? ``python def insert_after_broken(node, v): node.next = Node(v) ` Called on build(1, 2, 3) with node 1 and the value 9, it prints 1 -> 9 -> None`.
  5. 5. What is the bug in this function? ``python def remove_broken(head, target): prev = None cur = head while cur is not None and cur.val != target: prev = cur cur = cur.next if cur is None: return head prev.next = cur.next return head ` Removing 4 from 4 -> 5 -> 6 raises AttributeError`.

5 question(s) left on this page.

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