livepython.net

95. Python Program to Add Numbers Until the User Types 0

EasyInput loops

Overview

An input loop with a stop value: 0 means "that's all".

Problem Statement

Read whole numbers, one per line, until the user types 0. Then print the total of all the numbers before the 0. For example, for 5, 10, 3 and 0:

Total: 18

If the first number is 0, the total is 0. Numbers can be negative.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value per line; the last line is always 0. Example:

5
10
3
0

Output

The output for that example:

Total: 18

The tests try 4 different inputs.

Learn this firstChapter 11 · Python Input Loops: Keep Asking Until It's Right
solution.py
# write your code here

EXPECTED OUTPUT

1Total: 18

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.