56. Python Program to find Positive, Negative numbers and Zeros of given numbers.
How does this program work?
- In this program we are going to learn about how to find the Positve numbers, Negative numbers and Zeros of given real numbers using Python.
- Declare variable, and array elements can be stored in that variable.
- Each element is compared with 0, If the element is greater than 0 then the element is postive and the element is less than 0 then the element is negative otherwise the element is zero.
- After doing this for each element of the given array, then we get the postive, negative and zeros numbers of given numbers.
Here is the code
ar = (4,6,0,-5,8,-2,0)
print("Given numbers: ")
print(ar)
n=len(ar)
positive = 0
negative = 0
zero = 0
for i in range(n):
if (ar[i] > 0):
positive += 1
elif (ar[i] < 0):
negative += 1
else:
zero +=1
print("Number of +ve numbers are: ",positive)
print("Number of -ve numbers are: ",negative)
print("Number of Zeros are: ",zero)