Problems › Python › production
How busy was the line
A shift board shows what share of the planned time the line was actually running.
- A whole-number percentage, rounded half up.
- Running longer than planned still reads as 100 — the board does not show more than full.
- No planned time means no percentage: return 0.
utilisation_percent(run_minutes: int, planned_minutes: int) → int
Where you start
def utilisation_percent(run_minutes: int, planned_minutes: int) -> int:
Worked examples
| Call | Result |
|---|---|
utilisation_percent(420, 480) | 88 |
utilisation_percent(480, 480) | 100 |
utilisation_percent(500, 480) | 100 |
utilisation_percent(0, 480) | 0 |
Hint
Round first, then cap. Capping first hides the rounding.
Reference solution in Python
def utilisation_percent(run_minutes: int, planned_minutes: int) -> int:
if planned_minutes <= 0 or run_minutes <= 0:
return 0
pct = (run_minutes * 100 + planned_minutes // 2) // planned_minutes
return min(100, pct)