Answer to Question #251769 in Python for Hilok

Question #251769
1. Here is a list of integers. Find the elements that are the square of any number m.
2. The sequence of natural numbers a1, a2, ..., an is given. Replace the terms greater than the given number Z. with this number. Calculate the number of substitutions.
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-16T11:02:25-0400
# 1.
l = list(map(int,input("input space-separated integers:\n").split()))
sq = []
for i in range(len(l)):
	if l[i]**(1/2) == int(l[i]**(1/2)):
		sq.append(l[i])
print(*sq)


# 2.
s = list(map(int,input("input sequence of natural numbers:\n").split()))
z = int(input("Z = "))
cnt = 0
for i in range(len(s)):
	if s[i] > z:
		s[i] = z
		cnt += 1
print(f"number of substitutions: {cnt}")


# 3.
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