A driving school's pass rate is reported every year as a count: (passed, candidates). A local paper wants to print how the rate changed from last year to this year, and it wants both honest ways of saying it:
- the change in percentage points: this year's pass rate in percent minus last year's,
- the relative change in percent: how much bigger or smaller this year's rate is, as a percentage of last year's rate.
Write rate_change(before, after) that takes two (passed, candidates) pairs and returns the tuple (points, percent). If last year's pass rate was 0, a relative change cannot be computed, so percent is None. Do not round.
Examples
Input: before = (40, 100), after = (75, 150)
Output: (10.0, 25.0)
Explanation: the rate rose from 40% to 50%: 10 percentage points, which is 25 percent of 40.
Input: before = (18, 30), after = (27, 60)
Output: (-15.0, -25.0)
Explanation: 60% fell to 45%.
Input: before = (0, 12), after = (3, 10)
Output: (30.0, None)
Constraints
1 <= candidates <= 10**6and0 <= passed <= candidatesin both years- answers are compared with a small tolerance
Goals
- Compute a rate from a count and its total
- Tell a change in percentage points from a relative change in percent
- Refuse a relative change from a starting rate of zero