Python Program to Check Whether a Number is Positive or Negative or zero
Given a number. The task is to check whether the number is positive or negative or zero.
Input: 5 Output: Positive Input: -5 Output: Negative
We will use the if-elif statements in Python. We will check whether the number is greater than zero or smaller than zero or equal to zero.
Below is the implementation.
Positive Equal to zero Negative
The time complexity of this program is O(1). This is because all of the operations are performed in constant time, regardless of the size of the input. The program only performs three operations, so its time complexity remains constant regardless of the size of the input.
The space complexity of this program is also O(1). This is because the only additional space used is to store the input number, which is a constant size regardless of the size of the input.
Method: Using the list comprehension method