how can i return a tuple containing zero positives zero negatives?

Every loop, it is resetting result1, result2, and result3 to 0. Here’s better code:

def sign_counters(nums):
    """Returns a 3-tuple containing the number of negative values in nums, 
    the number of zero values in nums and the number of positive values in nums."""
    result1 = result2 = result3 = 0
    for num in nums:
        if num > 0:
            result1 += 1
        if num < 0:
            result2 += 1
        if num == 0:
            result3 += 1
    return result1, result2, result3

print(sign_counters([-1, 2, 0, -3, -1, 0]))
print(sign_counters([-1, -5, -3, -2]))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top