Python program to calculate the winner of well-known winner selection methods, including the plurality method, the runoff method, the elimination method, the Borda count, and the pairwise-comparison method (a.k.a. Condorcet method).
Python program to calculate the winner of well-known winner selection methods, including the plurality method, the runoff method, the elimination method, the Borda count, and the pairwise-comparison method (a.k.a. Condorcet mthod).
A,B,C,D
A,B,C,D
D,C,B,A
B,C,A,D
A,B,C,D
A,B,C,D
A,B,C,D
B,C,A,D
A,B,C,D
B,C,A,D
B,C,A,D
B,C,A,D
C,B,A,D
C,B,A,D
C,B,A,D
D,C,B,A
C,B,A,D
D,C,B,A
A,B,C,D
sc.py
at the command line with the csv file as an argument:$ python3 sc.py preferences.csv
-m
or --method
optional argument to specify a$ python3 sc.py preferences.csv -m borda
plurality
),runoff
),elimination
),borda
),pairwise
).$ python3 sc.py preferences.csv -m borda
Borda count
Preference Schedule:
Voter 1: A, B, C, D
Voter 2: D, C, B, A
Voter 3: B, C, A, D
Voter 4: A, B, C, D
Voter 5: A, B, C, D
Voter 6: A, B, C, D
Voter 7: B, C, A, D
Voter 8: A, B, C, D
Voter 9: B, C, A, D
Voter 10: B, C, A, D
Voter 11: B, C, A, D
Voter 12: C, B, A, D
Voter 13: C, B, A, D
Voter 14: C, B, A, D
Voter 15: D, C, B, A
Voter 16: C, B, A, D
Voter 17: D, C, B, A
Voter 18: A, B, C, D
Detailed Preference Schedule:
5 Voters: B, C, A, D
4 Voters: C, B, A, D
3 Voters: D, C, B, A
6 Voters: A, B, C, D
Borda scores: {'C': 52, 'A': 45, 'B': 56, 'D': 27}
The winner(s) is(are) ['B']