#比例代表選挙で用いられるドント方式のプログラム Tomei = ["A 党", "B 党", "C 党", "D 党"] Tokuhyo = [1200, 660, 1440, 180] Tosen = [0, 0, 0, 0] Hikaku = [0, 0, 0, 0] Koho = [5, 4, 2, 3] tosenkei = 0 giseki = 6 for m in range(4): Hikaku[m] = Tokuhyo[m] while tosenkei < giseki: max = 0 for i in range(4): if max < Hikaku[i] and Koho[i] >= Tosen[i] + 1: max = Hikaku[i] maxi = i Tosen[maxi] = Tosen[maxi] + 1 tosenkei = tosenkei + 1 Hikaku[maxi] = int(Tokuhyo[maxi] / (Tosen[maxi] + 1)) for k in range(4): print(Tomei[k],":",Tosen[k],"名")