Draw your first bar chart: one row per category, the bar's length equal to its value.
What to build
A program that prints a simple text bar chart.
Requirements
- For each category, in input order, print
LABEL | BAR VALUE, where LABEL is right-aligned to the length of the longest label and BAR is the value's number of#characters (empty for 0).
Input
Line 1: n. Then n lines LABEL VALUE, with whole-number values.
Output
n lines.
Constraints
1 ≤ n ≤ 20; 0 ≤ value ≤ 60; labels are single words.
Example
Input:
3
Tea 5
Coffee 8
Milk 2
Output:
Tea | ##### 5
Coffee | ######## 8
Milk | ## 2
Why it works
Right-aligning the labels makes every bar start in the same column, which is the shared baseline that makes lengths comparable.
Examples
Example 1 · Input
3 Tea 5 Coffee 8 Milk 2
Expected output
Tea | ##### 5 Coffee | ######## 8 Milk | ## 2
Example 2 · Input
2 a 0 bb 3
Expected output
a | 0 bb | ### 3
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Find the longest label first, then right-align every label to that width with an f-string.
Hint 2
'#' * value repeats the character value times.
Solution
Show one correct solution (try it yourself first)
n = int(input())
rows = []
for _ in range(n):
label, value = input().split()
rows.append((label, int(value)))
width = max(len(label) for label, _ in rows)
for label, value in rows:
print(f"{label:>{width}} | {'#' * value} {value}")