152k views
4 votes
Design a program that ask the user to enter a series of positive numbers. The user should enter a negative number to the series. After all the positive numbers have been entered the program should display their sum

User Kontekst
by
5.5k points

1 Answer

3 votes

Answer:

total = 0

while True:

number = float(input("Enter a number: "))

if number < 0:

break

total += number

print("The total of the positive numbers entered is", total)

Step-by-step explanation:

*The code is in Python.

Initialize the total as 0

Create a while loop. Inside the loop:

Ask the user to enter a number. Check the number. If it is smaller than 0 (This means it is a negative number), stop the loop using break. Add the number to the total (cumulative sum). (This way your program keeps summing numbers until you enter a negative number)

When the loop is done, print the total

User Catphive
by
5.4k points