Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import openpyxl
- from openpyxl import Workbook
- from openpyxl import load_workbook
- wb = load_workbook('STV.xlsx') #Replace with file name.
- ws = wb.active #Sets active sheet.
- votes = {} #Votes for each person.
- voters = {} #Voters for each person.
- voterNomLen = {} #Number of candidates each person has nominated.
- votersList = [] #List of voters.
- voterNum = 0 #Number of voters.
- minVotes = 0 #Minimum number of votes required to win.
- cansList = [] #List of candidates.
- invalCans = [] #Removed candidates.
- invalVoters = [] #Removed voters.
- winners = [] #List of winners.
- letterList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
- 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
- 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ',
- 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT',
- 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ']
- class STVfunctions:
- def __init__(self, ws, voterNum, votersList, voterNomLen):
- self.ws = ws
- self.voterNum = voterNum
- self.votersList = votersList
- self.voterNomLen = voterNomLen
- def voterNomLenFunction():
- for a in range(votersList):
- for b in range(50):
- if ws[letterList[a]+str(b)] == '':
- voterNomLen
- def votersListFunction(self):
- for i in range(50):
- if ws[str(letterList[i])+'1'] != 'BREAK':
- votersList.append(str(letterList[i]))
- else:
- return votersList
- def checkWin(votes):
- if votes[candidates[i]] >= minVotes:
- return True
- return False
- x = STVfunctions(ws, voterNum, votersList, letterList) #Sets up the class STVfunctions.
- votersList = x.votersListFunction()
- voterNum = len(votersList)
- minVotes = voterNum/3
- print(votersList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement