Opposite Signs Checker
Python code:
def check_opposite_signs(a, b):
if (a < 0 and b > 0) or (a > 0 and b < 0):
return True
else:
return False
# Test cases
print(check_opposite_signs(-3, 4)) # True
print(check_opposite_signs(4, 3)) # False
print(check_opposite_signs(0, 4)) # False
print(check_opposite_signs(8, 0)) # False
print(check_opposite_signs(0, -4)) # False
print(check_opposite_signs(-4, -8)) # False
print(check_opposite_signs(20000, -20001)) # True
print(check_opposite_signs(0, 0)) # False
Explanation:
- The function
check_opposite_signstakes two integersaandbas input. - It checks if
ais negative andbis positive, or ifais positive andbis negative. - If either of these conditions is true, it returns
True, indicating that the numbers have opposite signs. - Otherwise, it returns
False. - The test cases demonstrate the expected output for different combinations of numbers.