Answer to Question #270544 in Python for Aqsa

Question #270544

Write a program that reads an unspecified number of integers, determines how many positive

and negative values have been read, and computes the total and average of the input values (not

counting the zero). The program ends with the input 0. Display the average as a floating-point number


1
Expert's answer
2021-11-24T00:43:43-0500
sum1 = 0
count_pos = 0
count_neg = 0
while (True):
    i = float(input("Enter an integer (0 to stop): "))
    if i == 0:
        break
    sum1 += i
    if i > 0:
      count_pos += 1
    elif i < 0:
      count_neg += 1
print("The total number of positive numbers: ", count_pos)
print("The total number of negative numbers: ", count_neg)
print("The total sum: ", sum1)

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