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]
4 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]4 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
Se le conoce así cuando el analista mismo desarrolla el software necesario para implementar el diseño
kari74 [83]

Answer:

Desarrollo de software.

Explanation:

El método clásico de desarrollo de software se denomina modelo en cascada, lo que significa que cada fase de desarrollo del programa debe completarse antes de que comience la siguiente, y que se lleva a cabo un extenso trabajo de especificación antes de que comience el desarrollo real del programa. La especificación es tradicionalmente de arriba hacia abajo y el desarrollo se basa en una programación estructurada, es decir, se formula primero un objetivo final para el proyecto, y luego el programa se divide gradualmente en partes funcionales más pequeñas.

Los métodos más nuevos son ágiles y basados ​​en pruebas. Se basan en el desarrollo gradual de muchas entregas parciales del programa y permiten que las distintas fases de desarrollo se lleven a cabo de forma cíclica o en paralelo. Los clientes y usuarios ganan influencia a lo largo del proceso de desarrollo. El desarrollo y las pruebas de prototipos comienzan lo antes posible, antes de que estén listos todos los detalles de la especificación de requisitos. Las decisiones sobre la especificación de requisitos de las versiones de entrega se toman lo más tarde posible, cuando los usuarios han probado y comprendido lo que realmente quieren y existe un buen conocimiento de las necesidades, posibilidades técnicas y dificultades. Cambia entre el método de arriba hacia abajo (para comenzar desde el propósito y el objetivo) y el método de abajo hacia arriba (para comenzar con lo que ya tiene y puede reutilizar, y comenzar con casos especiales simples pero gradualmente hacer que el programa sea cada vez más general).

4 0
3 years ago
The space between the margin<br> and start<br> of paragraph is called
masya89 [10]

Answer:

The space between the margin and start of paragraph is called an indent OR Indentation.06

Explanation:

6 0
3 years ago
The Company should use BLANK cables to provide Fast connectivity without electrical interference
Lisa [10]

they should use Ethernet! it offers fast and easy setup, and is just plug and play!

3 0
3 years ago
The _______ is a small program run by a computer when first powered on. its primary function is to stabilize the machine and dev
tigry1 [53]
Hello <span>TheCelloAlex1645 </span>

Answer: <span>The BIOS is a small program run by a computer when first powered on. its primary function is to stabilize the machine and devices on the motherboard so that the operating system can be loaded and take control of the computer.


Hope this helps
-Chris</span>
3 0
4 years ago
Jack is part of the software quality assurance team in a company. Which activity should Jack perform as a part of software quali
gizmo_the_mogwai [7]

Answer:

C - testing

Explanation:

quality assurance is another name for verifying something. so when you verify software, you test the software.

3 0
3 years ago
Other questions:
  • Declare a character variable letterStart. Write a statement to read a letter from the user into letterStart, followed by stateme
    10·1 answer
  • Where may an operating system reside in a mobile device?
    5·1 answer
  • 4. A friend knows you are taking a technology class in college and asks you how a hard drive works. In your own words, describe
    6·1 answer
  • Which of the following is not true about a computer byte? A) It is made up of 8 bits. B) Each letter of the alphabet is stored i
    15·1 answer
  • If you attempt an edgeunity quiz is your latest attempt the one counted?
    10·1 answer
  • Meaning of page break​
    8·1 answer
  • Write a MATLAB script that prompts the user to input the following array by providing an example in the prompt: [2 4;6 3;5 9]. C
    15·1 answer
  • Make this the most answered question<br><br><br><br> (for tiktok)
    8·2 answers
  • Rube Goldberg project NEED HELP ASAP
    13·1 answer
  • Your client Mr. Smith has requested a reservation at Eleven Madison Park this evening for a party of 2 at 6PM. Unfortunately, th
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!