$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #99

Which fix removes the bug?

def price(v):
    assert v > 0, 'must be positive'
    return v * 2
  1. Raise explicitly: if v <= 0: raise ValueError
  2. Raise explicitly: if v <= 0: return ValueError
  3. Change the assert message to be clearer
  4. Move the assert below the return line
Assertions are stripped when Python runs with -O, so the check silently disappears.
Play Problem Solving ▸