asked 152k views
1 vote
Write a program that will ask the user to continuously input positive numbers until they type -1 to stop. The program should add up all the number they entered as they are typed ( excluding the -1) then print

example: user enters
8

4.

20

-1
Total: 32

asked
User Govert
by
7.3k points

1 Answer

4 votes

In python 3:

total = 0

while True:

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

if number == -1:

break

total += number

print("Total: {}".format(total))

I hope this helps!

answered
User Lindydancer
by
7.8k points

No related questions found