
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to find sign of the product of an array using Python
Suppose we have an array called nums. We have to find sign of the multiplication result of all elements present in the array.
So, if the input is like nums = [-2,3,6,-9,2,-4], then the output will be Negative, as the multiplication result is -2592
To solve this, we will follow these steps −
zeroes := 0,negatives := 0
for each i in nums, do
if i is same as 0, then
zeroes := zeroes + 1
if i < 0, then
negatives := negatives + 1
if zeroes > 0 , then
return "Zero"
otherwise when negatives mod 2 is same as 0, then
return "Positive"
otherwise,
return "Negative"
Let us see the following implementation to get better understanding −
Example
def solve(nums): zeroes,negatives = 0,0 for i in nums: if i == 0: zeroes+=1 if i < 0: negatives+=1 if zeroes > 0: return "Zero" elif negatives % 2 == 0: return "Positive" else: return "Negative" nums = [-2,3,6,-9,2,-4] print(solve(nums))
Input
[-2,3,6,-9,2,-4]
Output
Negative
- Related Articles
- Program to find the winner of an array game using Python
- Program to find maximum product of two distinct elements from an array in Python
- Python Program to Find the Product of two Numbers Using Recursion
- C++ program to find the first digit in product of an array of numbers
- Golang program to find the maximum product of two numbers in an array using two pointer approach
- Python program to find product of rational numbers using reduce function
- Program to find array of doubled pairs using Python
- Compute the sign and natural logarithm of the determinant of an array in Python
- Python program to find Cartesian product of two lists
- Python Program to find the sum of array
- Program to find out the number of shifts required to sort an array using insertion sort in python
- Java Program to Find the Product of Two Numbers Using Recursion
- Haskell Program to Find the Product of Two Numbers Using Recursion
- Golang Program to Find the Product of Two Numbers Using Recursion
- C++ Program to Find the Product of Two Numbers Using Recursion

Advertisements