gears = [20,20,30,35,36,40,40,40,42,45,48,50,50,54,57,60,60,70,80,80] def calculate_pitch(na, nb, nc, nd): p = na / nb * nc / nd * 1.5 e = abs(p - target_pitch) / target_pitch return (p, e) target_tpi = float(input("tpi : ")) target_pitch = 25.4 / target_tpi sol = [] t = len(gears) for a in range(t): r = set(range(t)) r.remove(a) na = gears[a] for b in r: s = set(r) s.remove(b) nb = gears[b] if (na + nb) >= 75 and (na + nb) <= 160: for c in s: nc = gears[c] u = set(s) u.remove(c) for d in u: nd = gears[d] if (nc + nd) >= 85 and (nc + nd) <= 140: pitch, error = calculate_pitch(na, nb, nc, nd) if error <= 0.005: v = (na,nb,nc,nd) if v not in sol: sol.append(v) print("Engrenages : {}".format(v)) print("Pas obtenu : {:.3f} mm".format(pitch)) print("Erreur : {:.3f}%".format(error * 100)) input() print("Nb solutions :", len(sol))