Data Visualization: A KPI card line

A KPI card shows a value with its change from the previous period. Format one.

What to build

A program that formats KPI card lines.

Requirements

  • For each KPI print NAME VALUE up X%, NAME VALUE down X% or NAME VALUE no change, with VALUE using comma thousands separators and X the size of the percentage change to one decimal.

Input

Line 1: n. Then n lines NAME VALUE PREVIOUS, whole numbers.

Output

n lines.

Constraints

1 ≤ n ≤ 20; 0 ≤ VALUE ≤ 10⁹; 1 ≤ PREVIOUS ≤ 10⁹.

Example

Input:

2
Revenue 12500 11500
Signups 90 120

Output:

Revenue 12,500 up 8.7%
Signups 90 down 25.0%

Why it works

Thousands separators make large numbers readable at a glance, and the change against the previous period gives the value the context that tells the reader whether it is good news.

Examples

Example 1 · Input
2
Revenue 12500 11500
Signups 90 120
Expected output
Revenue 12,500 up 8.7%
Signups 90 down 25.0%
Example 2 · Input
1
Orders 1000 1000
Expected output
Orders 1,000 no change

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

Hints

Hint 1

f"{value:,}" adds thousands separators to a whole number.

Hint 2

The change is (value − previous) ÷ previous × 100.

Solution

Show one correct solution (try it yourself first)
n = int(input())
for _ in range(n):
    name, value, prev = input().split()
    v, p = int(value), int(prev)
    if v == p:
        print(f"{name} {v:,} no change")
    else:
        word = "up" if v > p else "down"
        print(f"{name} {v:,} {word} {abs(v - p) / p * 100:.1f}%")

Lesson: Designing dashboards →