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
KiRa [710]
4 years ago
10

Write a program that reads in X whole numbers and outputs (1) the sum of all positive numbers, (2) the sum of all negative numbe

rs, and (3) the sum of all positive and negative numbers. The user can enter the X numbers in any different order every time, and can repeat the program if desired.
Computers and Technology
1 answer:
maxonik [38]4 years ago
5 0

Answer:

  1. run = 'y'
  2. sumPos = 0
  3. sumNeg = 0
  4. grandTotal = 0
  5. while run == 'y':
  6.    num = input("Enter a whole number: ")
  7.    while(num != 't'):
  8.        num = int(num)
  9.        if(num > 0):
  10.            sumPos += num  
  11.        else:
  12.            sumNeg += num  
  13.        
  14.        grandTotal += num
  15.        num = input("Enter a whole number: ")
  16.    
  17.    print("Sum of positive: " + str(sumPos))
  18.    print("Sum of negative: " + str(sumNeg))
  19.    print("Grand total: " + str(grandTotal))
  20.    sumPos = 0
  21.    sumNeg = 0
  22.    grandTotal = 0
  23.    run = input("Do you wish to continue (y/n): ")

Explanation:

Firstly, we get ready all the necessary variables (Line 1 -4) to track the running status, summation of positive, negative and grand total of all input numbers.

We create a while loop to keep our program running when run status is still equal to 'y' (Line 9).

Next we create if else statements to check if the number is positive or negative and add them to either sumPos or sumNeg (Line 11-14). The value of the grandTotal will be accumulated no matter the input number is positive or negative (Line 16). This process will repeat until user input "t".

Then we can display the sum of positive, negative and all numbers (Line 19-21) and reset the sumPos, sumNeg and grandTotal to 0 (Line 22-24).

At last we prompt user to input their choice is they wish to continue the program (Line 25).  

You might be interested in
What is the effect of flattening layers in image editing?
PolarNik [594]
The answer to this blanks are black and visible
6 0
3 years ago
Read 2 more answers
To find out how much ram is installed on a machine, in windows go to the user: a power ______ is a part inside a computer case t
shusha [124]
<span>a power _supply_ is a part inside a computer case that supplies power to the motherboard and other devices that are installed user: when a hard drive is first recognized by windows, it is assigned the _basic_ disk status user: utilize a _64_-bit os if you are looking for increased performance and you have a system that can support it.</span>
4 0
3 years ago
. What process skill would a scientist use to find the length of a line
Brilliant_brown [7]

Answer:

Explanation:

A ruler

;););););););););););););););)

7 0
3 years ago
Give the type and value of each result of the following Java expressions.
atroni [7]
Give the type and value of each result of the following Java expressions. a. (5 / 2) * 2.0  type is float value is 4.0 b. (5/2.0) * 2 type is integer value is 5c. "1.3" + "5.2" type is string value is 1.35.2d. 1 + 7.0 + "2" + "x"  this will produce an error because we cannot add variables of different type
3 0
3 years ago
In order, the three-step process of using a file in a C++ program involves
Anna71 [15]

Answer:

c. open the file, read/write/save data, close the file

Explanation:

8 0
4 years ago
Other questions:
  • What protocol must be supported by routers in order to utilize remote assistance easy connect?
    10·1 answer
  • Which is the output of the formula =AND(12&gt;6;6&gt;3;3&gt;9)
    6·1 answer
  • Given 3 floating-point numbers. Use a string formatting expression with conversion specifiers to output their average and their
    14·1 answer
  • Is ubisoft still making assassins creeds on xbox 360
    8·2 answers
  • You are driving on expressway with three lanes in your direction at a speed lower then
    8·2 answers
  • How are online sources used? Check all that apply.
    8·2 answers
  • What symbol indicates that material has been copyrighted?
    8·2 answers
  • February 1995, Kevin Mitnick was arrested. While on parole was he allowed to have a phone or computer?
    6·2 answers
  • Refund please, this has not helped at all.
    6·2 answers
  • Which option is typically only used when utilizing self joins?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!