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