Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 5 - Loops - Programming Exercises - Page 158: 5.1

Answer

Enter an integer, the input ends if it is 0 .... The Number of Positives is .... The Number of Negatives is .... The Total is .... The Average is ....

Work Step by Step

positives = 0 negatives = 0 count = 0 total = 0 n = eval(input("Enter an integer, the input ends if it is 0: ")) while n!=0: if n > 0: positives += 1 else: negatives += 1 count += 1 total += n n = eval(input("Enter an integer, the input ends if it is 0: ")) print("The number of positives is",positives) print("The number of negatives is",negatives) print("The total is",total) print("The average is",total*1.0/count)
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.