Run the pipeline

A CI pipeline runs steps in order and stops at the first failure, unless a step is marked optional. Simulate one.

What to build

A program that prints the log of a CI pipeline.

Requirements

  • Each step line is NAME RESULT or NAME RESULT optional; RESULT is pass or fail.
  • Go through the steps in order. A step before any failure is printed NAME: passed when it passes. If a step fails and it is not optional, print NAME: FAILED; every later step is then printed NAME: skipped.
  • A failing step that is optional prints NAME: failed (allowed) and the pipeline goes on.
  • Finally print result: green if no required step failed, otherwise result: red.

Input

The first line has n (1 to 20). Each of the next n lines is a step.

Output

One line per step, then the result.

Constraints

1 ≤ n ≤ 20.

Example

Input:

3
lint pass
tests fail
build pass

Output:

lint: passed
tests: FAILED
build: skipped
result: red

Why it works

One variable that remembers whether a required step has failed decides everything: before it is set the steps run normally, after it is set they are skipped, and the final result is read from the same variable.

Examples

Example 1 · Input
3
lint pass
tests fail
build pass
Expected output
lint: passed
tests: FAILED
build: skipped
result: red
Example 2 · Input
2
lint pass
build pass
Expected output
lint: passed
build: passed
result: green

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Keep a variable that remembers the first required failure.

Hint 2

After that failure, print skipped for every step.

Hint 3

A failing optional step is allowed: print its own message and go on.

Solution

Show one correct solution (try it yourself first)
n = int(input())
broken = False
for _ in range(n):
    parts = input().split()
    name, result = parts[0], parts[1]
    optional = len(parts) > 2 and parts[2] == "optional"
    if broken:
        print(f"{name}: skipped")
    elif result == "pass":
        print(f"{name}: passed")
    elif optional:
        print(f"{name}: failed (allowed)")
    else:
        print(f"{name}: FAILED")
        broken = True
print("result: red" if broken else "result: green")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Tests and continuous integration →