Sum Until Zero
Python
Easy
3 views
Problem Description
A list of integers is provided. Add numbers one by one until you see 0. Do not include 0 in sum. Output the sum.
Input Format
One line: integers separated by space (contains 0 at least once).
Output Format
One integer sum.
Constraints
At least one 0 is present. Total count
Official Solution
import sys
arr=sys.stdin.read().strip().split()
if not arr: sys.exit(0)
total=0
for tok in arr:
v=int(tok)
if v==0:
break
total+=v
sys.stdout.write(str(total))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!