1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergey [27]
3 years ago
6

Count positive and negative number and compute the average. The program will have the user input an unspecified number of intege

rs.
Determine how many are positive and negative.
Compute the total and average. Use a while loop.
Output as follows:
Enter an integer, the input ends if it is 0: 1 2 -1 3 0
The number of positives: 3
The number of negatives: 1
The total is 5.0
The average is 1.25
Computers and Technology
1 answer:
Alla [95]3 years ago
3 0

Answer:

The solution code is written in Python 3

  1. total = 0
  2. count = 0
  3. neg = 0
  4. pos = 0
  5. num = int(input("Enter an integer: "))
  6. while(num != 0):
  7.    total += num  
  8.    count += 1
  9.    if(num < 0):
  10.        neg += 1
  11.    else:
  12.        pos += 1
  13.    num = int(input("Enter an integer: "))
  14. print("The number of positives: " + str(pos))
  15. print("The number of negatives: " + str(neg))
  16. print("The total is " + str(total))
  17. print("The average is " + str(total/count))

Explanation:

Firstly, we create four variables, <em>total</em> , <em>count,</em> <em>neg</em> and <em>pos </em>(Line 1- 4). This is to prepare the variable to hold the value of summation of input integer (<em>total</em>), total number of input number (<em>count</em>), total negatives (<em>neg</em>) and total positives (<em>pos</em>).

Next, we prompt user for the first integer (Line 6).

Create a sentinel while loop and set the condition so long as the current input number, <em>num</em> is not equal to zero. the program will just keep adding the current <em>num</em> to total (Line 9)  and increment the count by one (Line 10).

if <em>num</em> smaller than zero, increment the <em>neg</em> by one (Line 13) else increment the <em>pos </em>by one (Line 15). This is to track the total number of positives and negatives.

Finally, we can display all the required output (Line 20 - 23) using the Python built-in function <em>print()</em>  when user enter 0 to terminate the while loop. The output shall be as follows:

The number of positives: 3

The number of negatives: 1

The total is 5

The average is 1.25

You might be interested in
Jacob is a website designer. Whenever his company takes on a new project, Jacob takes the initiative and comes up with ideas and
Troyanec [42]
Eating a potato is what hes using
3 0
2 years ago
What tabs found in the Windows Task Manager dialog box
fredd [130]
The applications you have open, and some background processes.
7 0
3 years ago
Stamps offers at-home postage and mailing for a monthly fee. Customers are able to carry a balance on their accounts that allows
alexdok [17]

Answer:

The pop-up button is necessary to show acceptance of the terms

Explanation:

5 0
3 years ago
Anyone knows the answer for 6.1.4 Happy Birthday! codehs
Neko [114]

cvm is good cvm is great

7 0
2 years ago
A software EULA is an agreement related to which of the following?
densk [106]

A software EULA is an agreement related to the terms of use of the software

the terms of use of the software

<u>Explanation:</u>

EULA stands for End User License Agreement. It can be defined as an agreement related to the terms of use of the software. EULA provides the user with all the details and any restrictions that have been imposed on the application by the developer.

In order to use the software, the user has to agree with all the terms and conditions specified in the EULA. The most common restriction imposed on an application/software is that it shouldn't be shared with anyone, in proprietary software.

7 0
3 years ago
Read 2 more answers
Other questions:
  • For C++ (please make sure it runs properly)
    14·1 answer
  • What would you use to compare two date ranges in a report?
    9·1 answer
  • 1. Caches are important to providing a high-performance memory hierarchy to processors. Below is a list of 32-bit memory address
    7·1 answer
  • Which attribute of the image tag specifies the URL of an image
    14·1 answer
  • In the ADT graph the methid addVertex has efficiency
    15·1 answer
  • Which of the following BEST describes an extranet?
    13·1 answer
  • A jackhammer uses pressurized gas to transmit force to the hammer bit. What type of mechanical system is it?
    13·1 answer
  • What is the difference between KE an PE
    8·1 answer
  • Which of the following is the most significant result of technological innovation?
    10·2 answers
  • Question #1
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!