Defects per thousand parts
Quality control reports scrapped parts as so many per thousand produced, truncated down.
- The rate is defects per thousand, truncated down.
- A run that produced nothing has no rate: return 0.
defects_per_thousand(defects: int, produced: int) → int
Where you start
def defects_per_thousand(defects: int, produced: int) -> int:
Worked examples
| Call | Result |
|---|---|
defects_per_thousand(500, 1000) | 500 |
defects_per_thousand(3, 10000) | 0 |
defects_per_thousand(1, 3) | 333 |
defects_per_thousand(2, 3) | 666 |
Hint
defects * 1000 / produced, guarding the divide by zero.
Reference solution in Python
def defects_per_thousand(defects: int, produced: int) -> int:
if produced <= 0:
return 0
return (defects * 1000) // produced