Embercode
✕
Linked ListsQuick quiz

Digit lists and pair swaps in Python

8 questions. Covers Rotate and swap linked list nodes in Python.

Questions 1 to 5 of 8

  1. 1. What does this print? It uses the lesson's add_two_numbers, from_digits and to_list helpers. ``python print(to_list(add_two_numbers(from_digits(9, 9), from_digits(1)))) ``
  2. 2. What does this print? ``python print(to_list(add_two_numbers(from_digits(9, 9, 9, 9, 9, 9, 9), from_digits(9, 9, 9, 9)))) ``
  3. 3. What does this print? It uses the lesson's rotate_right helper, with from_values and to_list. ``python print(to_list(rotate_right(from_values(1, 2, 3, 4, 5), 7))) ``
  4. 4. This loop is meant to add two digit lists. What does it return for 99 + 1, and what is wrong? ``python while a is not None or b is not None: total = carry if a is not None: total += a.val a = a.next if b is not None: total += b.val b = b.next tail.next = ListNode(total % 10) tail = tail.next carry = total // 10 ``
  5. 5. This line replaces the two if checks in the add loop. What happens when it runs for 342 + 65, and why? ``python total = a.val + b.val + carry ``

5 question(s) left on this page.