← Back to challenges

Positives and Negatives

PythonHardarraysnumbersloopsvalidation

Instructions

Create a function which validates whether a given list alternates between positive and negative numbers.

Examples

alternate_pos_neg([3, -2, 5, -5, 2, -8]) ➞ True

alternate_pos_neg([-6, 1, -1, 4, -3]) ➞ True

alternate_pos_neg([4, 4, -2, 3, -6, 10]) ➞ False

Notes

  • Lists can be of any length.
  • It doesn't matter if a list begins/ends with a positive or negative, as long as it alternates.
  • If a list contains 0, return False (as it is neither positive nor negative).
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.