BugLab019 / 020up to 100
booleanstruthinesscomparisoneasy

Misleading Truth

The function is_positive(n) should return True if n is strictly greater than zero, and False for zero and all negative numbers.

It works correctly for positive numbers and for zero. But it incorrectly returns True for negative numbers.

In Python, many values are considered "truthy" — but truthy and positive are not the same thing.

hint 2after hint 1
hint 3after hint 2
solution

Read the code. Before running anything: what does the last line below give?

def is_positive(n):
"""
Returns True if n is strictly greater than zero.
Returns False for zero and all negative numbers.
Example: is_positive(5) -> True
is_positive(-3) -> False
"""
if n:
return True
return False
>>> is_positive(-3)