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
Which of the following commands would instruct OSPF to advertise ONLY the 192.168.10.0/24 network in Area 0?
xz_007 [3.2K]

Answer:

First, you need to start the OSPF process by executing the command:

<em>Router (config)# router ospf {process-ID#}</em>

Then, you have to instruct the router to advertise the networks that are directly linked to it by entering this network command with the area ID number for that network:

Router (config-router)# network {192.168.10.0} {255.255.255.0} area {0}

8 0
3 years ago
What is income?
s2008m [1.1K]
I think its D hope this help
5 0
3 years ago
Read 2 more answers
Please hurry Arrange the steps of the engineering design process in the correct sequence.
AnnZ [28]

Answer:The Nine steps  of the engineering design process

  1. <u>Identify the Problem</u>-Defining the problem
  2. Finding solutions through Brainstorming technique
  3. Conducting a background research/Survey
  4. Developing the solution-Creating an array of solutions
  5. Selecting the best solution
  6. Building a prototype
  7. Testing and redesigning
  8. Improve the design-Specifying the requirement
  9. Communicating the result

6 0
3 years ago
The term ____ is a technical term for the region of memory that holds data waiting to be transferred from one device to another.
shutvik [7]
<span>buffer is what your looking for    my friend made this  it should help  https://quizlet.com/20507517/ch-4-operating-systems-and-file-management-flash-cards/</span>

8 0
3 years ago
What does =SUM(B2:B6) mean
dedylja [7]

In Excel the sum B2 and B6 simply means that B2 and B6 Numbers are adding to get a Sum, it actually like the normal Calculator, but in Excel it helps to do the calculation of your your data simple and easy, there is no hard work.

8 0
2 years ago
Other questions:
  • What might be the best response to a cyberbuly attack
    6·2 answers
  • Explique si en la pc que se usa para hacer las tareas escolares se puede ver un video juego de los llamados “pesados”
    13·1 answer
  • What should be included as part of the approval process? in relation to computer forensics
    14·1 answer
  • Computer hardware without computer software is useless while computer software without computer hardware is meaningless. Discuss
    10·1 answer
  • Instructions:Select the correct answer from each drop-down menu. What type of font color should Kim select if she chooses a dark
    10·2 answers
  • The CSS property of top , bottom , left , or right moves the element the specified distance from the respective edge of the clos
    7·1 answer
  • You’re having trouble connecting to the Internet so you call your Internet service provider for help. They need to know the perm
    15·1 answer
  • In science class, Patricia is giving a presentation on the different types of flowers in her community. As part of her presentat
    5·1 answer
  • EMERGENCY- I am giving 55 points for this, please help. WITH working out
    7·1 answer
  • What does the word collaborative mean?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!