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
Write a function (subroutine) that inputs a data value in register r0 and returns value in r0. The function returns y 5 a 1 bx 1
umka2103 [35]

Solution :

  int f(int x){

      \text{return a + b*x +c*x*x};

  }*/

  int f(\text{int R0}){

      int stack[2] = {\text{R1,R2}};

      \text{R1 = R0};

      \text{R1 = R1}\times \text{ R1};

      \text{R2 = C};

      R1 = R1 * C; /*R1 = cx^2*/

      \text{R2 = B};

      \text{R0 = R0} * R2; /* R0 = bx */

      \text{R0 = R0 + R1}; /*R0 = bx + cx^2 */

      \text{R2 = C};

      \text{R0 = R0 + R2}; /*R0 = a+bx+cx^2 */

      \text{R1 = stack[0];}

     \text{ R2 = stack[1];}

     \text{ return R0;}

  }

  /*\text{ARM code to implement the following C operation}

  int s=0;

  \text{for ( i = 0; i < 10; i++)}

  { \text{s = s + i } \times i;)

  */

          AREA SumSquares, code, readWrite

          ENTRY

          \text{MOV r0, #0}        ;loop \text{ counter i present at 0}

          MOV r1, #0       ; s = 0

  Loop   \text{MUL r2, r0, r0}   ;calculate i*i

          \text{ADD r1, r1, r2}   ;s = s+ i*i

          \text{ADDS r0, r0}, #1   ; i = i+1

          \text{CMP r0},#10       ; test for end

          \text{BNE} Loop        ; \text{continue until all added}

          END

5 0
3 years ago
Allan needs to ensure that an object is in a very precise location on a slide. He decides to use the Ruler option to achieve thi
shusha [124]

Answer:

It can be found on View tab.

Explanation:

The view tab on Microsoft Power point is the 9th tab when counting from the left. When clicked, the view tab displays a number of tools that are aimed at visualizing how slides appear.

The ruler function is one of those tools. It is used to ensure that an object is placed or appears at a specific location in the slides. The ruler tool can be found in the Show Box which is the third box from left after Presentation View and Master View.

8 0
3 years ago
Read 2 more answers
If you’re presenting in a darkened room, what text and background should you use to provide maximum readability?1) Light text on
ludmilkaskok [199]

Answer:

1

Explanation:

1 because it would be difficult for people to read on the other ones that you put.

3 0
3 years ago
William brought some data into his Tableau Book, but the data had some null values and incorrect column headers. What did Willia
ozzi

William  had to manually edit the data if he wants to remove the null values and incorrect column headers.

<h3>What is data editing?</h3>

Data editing is known to be a term that connote the act of making changes, reviewing or adjustment  some survey data.

Note that by editing one can remove want one do not want from a group of data and as such,  William  had to manually edit the data if he wants to remove the null values and incorrect column headers.

Learn more about data from

brainly.com/question/26711803

#SPJ1

6 0
2 years ago
Which action will help you protect data in your computer in case of an earthquake?
Len [333]

Answer:

Explanation: 13

8 0
3 years ago
Read 2 more answers
Other questions:
  • What is cyberbullying?
    14·2 answers
  • The most common solution to supply chain uncertainties is to build inventories or __________ as insurance.
    6·1 answer
  • Briefly define "address space" and discuss its major tradeoffs (advantages/costs). What problem is it addressing?
    10·1 answer
  • Select the correct answer from each drop-down menu.
    8·1 answer
  • Victor works for a telemarketing company that is on a very tight budget. He has been tasked with finding a method for the compan
    7·2 answers
  • How do I delete my brainly account?<br> I don't need anymore.
    13·2 answers
  • Please be my friend. my best and only friend isn't talking to me for some reason
    9·2 answers
  • 1. Which of the following cables are used in networking? Check all that apply.
    8·2 answers
  • EXPLAIN WHY CRYPTOCURRENCIES ARE NOT RELIABLE.
    5·1 answer
  • What is bigger that terbites
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!