Drill

ProblemsPython › machines

Defects per thousand parts

easymachinesPython

Quality control reports scrapped parts as so many per thousand produced, truncated down.

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

Solve it in the editor →

Where you start

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

Worked examples

CallResult
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

The same problem in another language

More machines problems in Python