Drill

ProblemsPython › production

Defects per million parts

easyproductionPython

Quality reports the defect rate in parts per million, because "0.03%" is harder to compare across lines than "300 ppm".

defect_ppm(defects: int, produced: int) → int

Solve it in the editor →

Where you start

def defect_ppm(defects: int, produced: int) -> int:
    

Worked examples

CallResult
defect_ppm(3, 10000)300
defect_ppm(0, 10000)0
defect_ppm(1, 3)333333
defect_ppm(2, 3)666667

Hint

defects * 1000000 / produced, with half the divisor added before dividing so it rounds instead of truncating.

Reference solution in Python
def defect_ppm(defects: int, produced: int) -> int:
    if produced <= 0:
        return 0
    return (defects * 1000000 + produced // 2) // produced

The same problem in another language

More production problems in Python