Data Visualization: Progress against a target

A KPI card compares a value with its target, shows a small progress bar and a status word.

What to build

A program that prints target progress for KPIs.

Requirements

  • For each KPI print NAME [BAR] P% STATUS, where P is the progress rounded to a whole number and BAR has 10 characters: int(progress ÷ 10) # characters (at most 10) followed by - characters.
  • STATUS is on track for a progress of 100 or more, at risk for 90 or more, otherwise off track.

Input

Line 1: n. Then n lines NAME VALUE TARGET.

Output

n lines.

Constraints

1 ≤ n ≤ 20; 0 ≤ VALUE ≤ 10⁹; TARGET is over 0.

Example

Input:

2
Sales 95 100
Leads 120 100

Output:

Sales [#########-] 95% at risk
Leads [##########] 120% on track

Why it works

Dividing by the target puts every KPI on the same 0–100% footing, the capped bar shows progress at a glance, and the status word repeats the message for readers who cannot rely on colour.

Examples

Example 1 · Input
2
Sales 95 100
Leads 120 100
Expected output
Sales [#########-] 95% at risk
Leads [##########] 120% on track
Example 2 · Input
1
Tickets 30 50
Expected output
Tickets [######----] 60% off track

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

Hints

Hint 1

The progress is value ÷ target × 100.

Hint 2

The bar has 10 characters: int(progress ÷ 10) of them `#`, at most 10, and the rest `-`.

Solution

Show one correct solution (try it yourself first)
n = int(input())
for _ in range(n):
    name, value, target = input().split()
    p = float(value) / float(target) * 100
    filled = min(10, int(p / 10))
    bar = "#" * filled + "-" * (10 - filled)
    status = "on track" if p >= 100 else "at risk" if p >= 90 else "off track"
    print(f"{name} [{bar}] {p:.0f}% {status}")

Lesson: Designing dashboards →