Embercode
✕
Variables and Data TypesQuick quiz

Uninitialised values and booleans

7 questions. Covers Booleans and the = trap in Python.

Questions 1 to 5 of 7

  1. 1. What happens when this program runs? ``python values = [1, 2] for v in values: if v > 2: largest = v print(largest) ``
  2. 2. What does this program print? ``python def biggest_with_zero(values): best = 0 for v in values: if v > best: best = v return best print(biggest_with_zero([-2, -8])) ``
  3. 3. What does this program print? ``python is_open = False if (is_open := True): print('open') print(is_open) ``
  4. 4. Why does Python reject if count = 0: but accept if (flag := False):?
  5. 5. What happens in Python when code reads a name that was never assigned on that path?

5 question(s) left on this page.