In: Computer Science
python question:
Problem Statement Given a list of integers input_list, loop through every element in the list to find the product of all positive integers and the count of all negative integers. The code to get the input_list is provided for you. The first line of code provided gets the size of the list. The remaining lines of code provided get the elements of the list. The provided data preprocessing code reads in these values and creates a list of ints for you.
Python code:
#accepting size
size=int(input())
#accepting all inputs and adding them to input_list
input_list=[int(input()) for i in range(size)]
#initializing count as 0
count=0
#initializing product as 1
product=1
#looping through all items in input_list
for i in input_list:
#checking if the number is positive
if(i>=0):
#multiplying product
with current number
product*=i
else:
#incrementing count of
negative numbers
count+=1
#printing Product
print("Product of all positive integers: "+str(product))
#printing Count
print("Count of all negative integers: "+str(count))
Screenshot:
Input and Output: