Respuesta :
Answer:
- run = 'y'
- sumPos = 0
- sumNeg = 0
- grandTotal = 0
- while run == 'y':
- num = input("Enter a whole number: ")
- while(num != 't'):
- num = int(num)
- if(num > 0):
- sumPos += num
- else:
- sumNeg += num
- grandTotal += num
- num = input("Enter a whole number: ")
- print("Sum of positive: " + str(sumPos))
- print("Sum of negative: " + str(sumNeg))
- print("Grand total: " + str(grandTotal))
- sumPos = 0
- sumNeg = 0
- grandTotal = 0
- 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).