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
The fast movement of briefly flashed images in an animated motion picture produces what effect? subliminal messaging convergence
REY [17]

Answer:

The answer is Stroboscopic movement

Explanation:

Stroboscopic movement occurs when we do not see a motion continuously but in discrete shots. It is an effect in which we see an object at one place and after another instant the object seems to have shifted it's position.

Auto kinetic effect is an effect in which a stationary point of light appears to move.It occurs as our brains can perceive motion relative to some other object and cannot observe ,motion along a featureless terrain or environment.

Phi effect causes an observer to perceive motion in stationary objects.

3 0
2 years ago
1. The Forever block is present in the<br> ......... block category.
rosijanka [135]

Answer:

loop or a repeating block. I think it’s this because I like robotics and I have to know a lot of different kinds of blocks.

Explanation:

This is why.

8 0
1 year ago
안녕 또 나야 난 너에게 미래의 메시지를 전하러 왔어 01100011 01101111 01101101 01101111 00100000 01111001 00100000 01101100 01101111 00100000 01101101
sashaice [31]

Answer:

i think its 01100001

Explanation:

4 0
2 years ago
Read 2 more answers
Which of the following is not one of the Fatal Four events that cause three out of five construction worker deaths? A. Caught in
k0ka [10]

The answer is D: Struck down.

Options A, B, and C are the most common types of fatal construction accidents in the United States. Falls, electrocutions, being struck by an object, and workers caught in or between things are responsible for over 64% of construction workers death. Among these four events, falls kill most construction workers followed by electrocutions, falling objects, and workers caught in or between things.


5 0
3 years ago
Read 2 more answers
A machine is a group of mechanical devices that transfer ___ input at one device into output at another device.
Arisa [49]
Ay 
Fonsi 
DY 
Oh
Oh no, oh no
Oh yeah
Diridiri, dirididi Daddy 
GoSí, sabes que ya llevo un rato mirándote 
Tengo que bailar contigo hoy (DY) 
Vi que tu mirada ya estaba llamándome 
Muéstrame el camino que yo voy (Oh)Tú, tú eres el imán y yo soy el metal 
Me voy acercando y voy armando el plan 
Solo con pensarlo se acelera el pulso (Oh yeah)Ya, ya me está gustando más de lo normal 
Todos mis sentidos van pidiendo más 
Esto hay que tomarlo sin ningún apuroDespacito 
Quiero respirar tu cuello despacito 
Deja que te diga cosas al oído 
Para que te acuerdes si no estás conmigoDespacito 
Quiero desnudarte a besos despacito 
Firmo en las paredes de tu laberinto 
Y hacer de tu cuerpo todo un manuscrito (sube, sube, sube)
(Sube, sube)Quiero ver bailar tu pelo 
Quiero ser tu ritmo 
Que le enseñes a mi boca 
Tus lugares favoritos (favoritos, favoritos baby)Déjame sobrepasar tus zonas de peligro 
Hasta provocar tus gritos 
Y que olvides tu apellido (Diridiri, dirididi Daddy)Si te pido un beso ven dámelo 
Yo sé que estás pensándolo 
Llevo tiempo intentándolo 
Mami, esto es dando y dándolo 
Sabes que tu corazón conmigo te hace bom, bom 
Sabes que esa beba está buscando de mi bom, bom 
Ven prueba de mi boca para ver cómo te sabe 
Quiero, quiero, quiero ver cuánto amor a ti te cabe 
Yo no tengo prisa, yo me quiero dar el viaje 
Empecemos lento, después salvajePasito a pasito, suave suavecito 
Nos vamos pegando poquito a poquito 
Cuando tú me besas con esa destreza 
Veo que eres malicia con delicadezaPasito a pasito, suave suavecito 
Nos vamos pegando, poquito a poquito 
Y es que esa belleza es un rompecabezas 
Pero pa montarlo aquí tengo la piezaDespacito 
Quiero respirar tu cuello despacito 
Deja que te diga cosas al oído 
Para que te acuerdes si no estás conmigoDespacito 
Quiero desnudarte a besos despacito 
Firmo en las paredes de tu laberinto 
Y hacer de tu cuerpo todo un manuscrito (sube, sube, sube)
(Sube, sube)Quiero ver bailar tu pelo 
Quiero ser tu ritmo 
Que le enseñes a mi boca 
Tus lugares favoritos (favoritos, favoritos baby)Déjame sobrepasar tus zonas de peligro 
Hasta provocar tus gritos 
Y que olvides tu apellidoDespacito 
Vamos a hacerlo en una playa en Puerto Rico 
Hasta que las olas griten "¡ay, bendito!" 
Para que mi sello se quede contigoPasito a pasito, suave suavecito 
Nos vamos pegando, poquito a poquito 
Que le enseñes a mi boca 
Tus lugares favoritos (favoritos, favoritos baby)Pasito a pasito, suave suavecito 
Nos vamos pegando, poquito a poquito 
Hasta provocar tus gritos 
Y que olvides tu apellido (DY)
Despacito
7 0
3 years ago
Other questions:
  • The sum of all the minterms of a boolean function of n variables is equal to 1.
    7·1 answer
  • Difference between change management n asset management
    11·1 answer
  • 7. The penalties for a first-time DUI charge include a fine of __________. A. up to $500 for a BAL of .08 to .15 B. $500-$1,000
    5·1 answer
  • Hello my friends i am trying to reboot my i phone 4 but i could not i tried many ways can u help me
    14·1 answer
  • Which of the following is NOT a data type in Python?<br> integer<br> decimal<br> string<br> float
    15·1 answer
  • A ____________ is a collection of commands given a name.
    11·1 answer
  • Write a C function named apply_all that expects two arrays of integers and their sizes and dynamically allocates a new array of
    7·1 answer
  • 1. Open command prompt
    5·1 answer
  • The second generation of computer languages is a higher-level language than
    14·1 answer
  • in a block in a blockchain what represents the transactional data, sender, receiver, and number of coins? group of answer choice
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!