In: Computer Science
Convert the following text into a code format:
The program reads an unspecified number of integers until a zero is entered. While the program reads each number it counts the number of positive numbers and the number of negative numbers that have been entered and sum up the values of the numbers entered. After the user enters zero, the program computes the average of the input values, not counting the zero. At the end, the program displays the average, and the counts of positive numbers and negative numbers
Answer:- We can do this problem using Python3 programming language
Python Code
q=[]
pCount=0
nCount=0
while (True):
a=int(input('Enter a integer: '))
if a==0:
break
else:
q.append(a)
if a<0:
nCount=nCount+1
else:
pCount=pCount+1
print("Average of numbers:",(sum(q)/(nCount+pCount)))
print("Counts of positive numbers:",pCount)
print("Counts of negative numbers:",nCount)
Output:-
If you need any help in understanding, please comment your query.
I tried my best for this question, I hope you upvote my answer.
Thank You