Data science: Did the training help?

People took a typing test before and after a training course. Measure what changed.

What to build

A program that reports the changes between two measurements of the same people.

Requirements

  • Print average change: +X (the mean of after − before, with its sign and two decimals).
  • Print improved: K, worse: K and same: K (how many changes were positive, negative and zero).
  • Print biggest gain: NAME (+X) for the largest positive change (the first one if several are equal), or biggest gain: none if nobody improved.

Input

Line 1: n. Then n lines NAME BEFORE AFTER.

Output

Five lines.

Constraints

1 ≤ n ≤ 100; values are numbers between 0 and 200.

Example

Input:

4
Ana 40 52
Bo 55 50
Cy 38 45
Di 60 60

Output:

average change: +3.50
improved: 2
worse: 1
same: 1
biggest gain: Ana (+12.00)

Why it works

Measuring the same people twice lets each person act as their own comparison, so the change per person is a fairer measure than comparing two separate groups, and counting who improved shows whether an average hides mixed results.

Examples

Example 1 · Input
4
Ana 40 52
Bo 55 50
Cy 38 45
Di 60 60
Expected output
average change: +3.50
improved: 2
worse: 1
same: 1
biggest gain: Ana (+12.00)
Example 2 · Input
2
X 10 8
Y 20 15
Expected output
average change: -3.50
improved: 0
worse: 2
same: 0
biggest gain: none

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

Hints

Hint 1

The change for each person is after − before; f"{x:+.2f}" prints a number with its sign.

Hint 2

Track the biggest gain with a variable that starts as None and is replaced only by a strictly larger positive change.

Solution

Show one correct solution (try it yourself first)
n = int(input())
changes = []
best = None
for _ in range(n):
    name, before, after = input().split()
    change = float(after) - float(before)
    changes.append(change)
    if change > 0 and (best is None or change > best[1]):
        best = (name, change)

print(f"average change: {sum(changes) / n:+.2f}")
print("improved:", sum(1 for c in changes if c > 0))
print("worse:", sum(1 for c in changes if c < 0))
print("same:", sum(1 for c in changes if c == 0))
if best is None:
    print("biggest gain: none")
else:
    print(f"biggest gain: {best[0]} ({best[1]:+.2f})")

Lesson: What data science is →