Generator Pipeline

Lab Python Advanced 30 points

Read lines until END. Build a pipeline of generators: read_lines() → non_empty(lines) (skip blank lines) → numbers(lines) (keep only lines that are integers) → total. Print the total.

Input

Lines of text, then END.

Output

The total.

Example

Input

10

hello
-4
  7  
END

Output

13
Sample input available Sample output available
Editor
Python

Hints

Each stage takes an iterable and yields values to the next stage.

The walrus operator := assigns inside an expression.

Solution explanation

Pipelines of generators process data one item at a time — like Unix pipes.

Show solution
def read_lines():
    while (line := input()) != "END":
        yield line


def non_empty(lines):
    for line in lines:
        if line.strip():
            yield line.strip()


def numbers(lines):
    for line in lines:
        if line.lstrip("-").isdigit():
            yield int(line)


print(sum(numbers(non_empty(read_lines()))))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD