Answer to Question #251455 in Python for Holik

Question #251455
3. The sequence of natural numbers a1, a2, ..., an is given. There are positive and negative elements in the chain. Calculate the product of negative elements P1 and the product of positive numbers P2. Compare the modules P2 and P1, indicate which of the modulus is greater.
1
Expert's answer
2021-10-16T13:53:18-0400
s_1 = list(map(int,input("input sequence of natural numbers:\n").split()))
pos, neg = 1, 1
for num in s_1:
	if num > 0:
		pos *= num
	elif num < 0:
		neg *= num
if abs(pos) > abs(neg):
	print("product of positive numbers greater")
elif abs(pos) < abs(neg):
	print("product of negative elements greater")
else:
	print("product of negative elements eqval product of positive numbers")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS