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
What is a limitation of 5G mmWave, despite its high speed?
Allushta [10]

The limitation of 5G mmWave, despite its high speed, is the fact that they have a short range.

  • 5G simply means the fifth generation of wireless technology that has great speed and provides connectivity to cellphones.

  • mmWave is the higher frequency radio band that is very fast. It should be noted that the 5G mmWave is super fast and is being used by large organizations to improve their work.

  • The main limitation of 5G mmWave is that for one to use it, one has to be close to the 5G tower. This is why it's hard for people living in rural areas to benefit from it unless it's situated close to them.

  • It should be noted that despite the fact 5G offers greater bandwidth, which is vital in relieving network congestion, there are still more improvements to be made in order for everyone to benefit.

In conclusion, the limitation of 5G mmWave, is that they have a short range.

Read related link on:

brainly.com/question/24664177

6 0
2 years ago
Which sequence represents the hierarchy of terms, from smallest to greatest?
Anni [7]

Answer:

b

Explanation:

7 0
2 years ago
A security utility program that scans the system for small programs that interfere with how a computer functions are _____ utili
Aneli [31]

Answer:

A security utility program that scans the system for small programs that interfere with how a computer functions are _____ utilities.

Explanation:

7 0
3 years ago
Which function of NOS involves swapping programs and files
yaroslaw [1]
The answer is Multitasking. NOS (Network Operating System) has the ability to execute more than one program at a time.  It allows different programs to operate on the CPU, effectively giving each program a virtual copy of the CPU while preventing the program from directly manipulating the hardware. The NOS switches the CPU time from one task  to another in order to create the idea that several tasks are being executed at the same time, but in reality, only one program is being executed. 
6 0
3 years ago
3.3 Code Practice: Question 1
Bezzdna [24]

Answer:

day=int(input(“Enter today’s day numerically: ”))

if(day ==15 or day ==30):

print(“It’s payday!”)

if(day !=15 and day !=30):

print(“Sorry, not a payday.”)

Explanation:Good luck!

6 0
3 years ago
Other questions:
  • Suppose that a computer virus infects your computer and corrupts the files you were going to submit for your current homework as
    12·1 answer
  • A very simple device that connects network components and sends packets of data to all other connected devices is called a _____
    5·1 answer
  • A ____ client locates all or most of the processing logic on the server.
    11·1 answer
  • Which describes which CTSO each student should join?]
    7·1 answer
  • The stack pop operation
    10·1 answer
  • What is wrong with question four? Find the error and then correct it
    11·1 answer
  • FREE 25 POINTS
    5·2 answers
  • There is an interface I that has abstract class AC as its subclass. Class C inherits AC. We know that C delegates to an object o
    12·1 answer
  • All of the following are true of using the database approach to managing data except Group of answer choices Decentralized manag
    6·1 answer
  • The technique that allows you to have multiple logical lans operating on the same physical equipment is known as a.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!