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
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
svlad2 [7]

Answer:

The program in Python is as follows:

currentPrice = int(input("Current: "))

lastMonth = int(input("Last Month: "))

print("The house is $",currentPrice)

print("The change is $",(currentPrice-lastMonth),"since last month")

print("The estimated monthly mortgage is $",(currentPrice * 0.051) / 12)

Explanation:

Get input for current price

currentPrice = int(input("Current: "))

Get input for last month price

lastMonth = int(input("Last Month: "))

Print current price

print("The house is $",currentPrice)

Print change since last month

print("The change is $",(currentPrice-lastMonth),"since last month")

Print mortgage

print("The estimated monthly mortgage is $",(currentPrice * 0.051) / 12)

6 0
3 years ago
What project started the development of inter-network connections using tcp/ip that has evolved in to the internet today
Vinvika [58]
The <span>ARPANET </span><span>project started the development of inter-network connections using TCP/IP that has evolved in to the internet today</span>
4 0
3 years ago
In which stage of the SDLC is it most appropriate to use prototyping?
bixtya [17]

<u>Answer:</u>

<em>When system feasibility is being determined </em>

<u>Explanation:</u>

<em>Prototyping is the part of Requirement and Analysis phase. </em>It is the phase where the client and the development team sits and discuss about what the requirement is and show <em>a model of what are all the things which they could bring up the requirement as a software. </em>

So here, the prototyping is really essential to visually understand how the team has interpreted the requirement and how far it matches with the client. <em>All the other options stands invalid in the given context.</em>

7 0
3 years ago
Read 2 more answers
Engineers must ______ with clients to show how their solution is the best one possible.
DIA [1.3K]
Hi there!

Since there are no options given in your question I will say that the answer is as follows.

<span>Engineers must communicate with clients to show how their solution is the best one possible.

Communication is key in business when trying to get your point across or when you need to know what a client or partner wants or has planned. Without communication, we could not explain or show anyone how your solution is the best one there is available no matter what else competition might have to offer.

-Sincerely your friend in tech, 
</span><span>ASIAX </span><span>  </span><span>Frequent Answerer</span>
3 0
3 years ago
What tells the hardware what to do and how to do it?
oksano4ka [1.4K]

Answer:

I think its CPU

Explanation:

8 0
3 years ago
Other questions:
  • When making college visits, you may be able to....
    9·2 answers
  • What is Tone's Core Move call in Titan Fall 2?
    5·1 answer
  • The default ____ for a hyperlink is the folder location and the name of the file to which you will link.
    6·1 answer
  • Which component is a part of the CPU of a computer
    12·2 answers
  • Which of the following statements opens the file info.txt for both input and output? a) dataFile.open("info.txt", ios::in &amp;&
    11·2 answers
  • Select the qualification that is best demonstrated in each example. Trinity recommends investment strategies to customers. Laris
    10·2 answers
  • System software includes all of the following except
    10·1 answer
  • Which term describes a number in base 16, using the digits from zero to nine along with A, B, C, D, E, and
    9·1 answer
  • Which key doesn't relate to keyboard
    6·2 answers
  • Does CLAIRE https://claire-ai.org/vision/ considered a representative of Roy Rotwell's Fifth Generation of innovation?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!