Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Elections
#1
I'm working on a problem here and it's quite a challenge. I just need some clarifications on some of the functions.

overview
The Government of Nerdvana conducts its elections using an unusual system. Each constituency elects one member to the Nerdvanian Parliament, and each voter casts one ballot in which they can assign any non-negative number of votes to each candidate. Each ballot paper is normalised to a total value of 1 before being counted: for example, given four candidates, the ballot paper .

First task is to open the file contaning the candidates which I have done:
def getCandidates(f):
    
    try:
        filename = open(f,'r')
        line = filename.read()
        line=[line.replace('\n', ",")]
        print(line)
        
    except IOError:
        print("File not found.", [])
Second task parseVote(s) returns the vote from s. Return 0 for an empty vote, and -1 if there are any non-digits (other than spaces)

def parseVote(s):
    if s == []:
        print("0")
    elif [ s != [0-9] ]:
        print("-1")
    else:
        print(s)       //Not sure if this is really correct.
I have a problem with the 3rd function that should return the votes from the ballot paper s in an election with n candidates, plus an error message if appropriate. If s is formal, return the list of numbers found in s and the empty string; if s is informal, return an empty list of numbers and the appropriate string below. def parsePaper(s,n):

Could someone explain how to get about the 3rd function? This function uses function 2

The foorth function should just read the votes from a file and pass to the above function.
Reply


Messages In This Thread
Elections - by nacerr - Apr-21-2017, 07:35 AM
RE: Elections - by idontreallywolf - Apr-21-2017, 08:35 AM
RE: Elections - by nacerr - Apr-21-2017, 09:19 AM
RE: Elections - by nacerr - Apr-21-2017, 01:40 PM
RE: Elections - by PythonHatesMe - Apr-25-2017, 06:24 AM
RE: Elections - by nacerr - Apr-25-2017, 06:27 AM
RE: Elections - by PythonHatesMe - Apr-25-2017, 06:40 AM
RE: Elections - by nacerr - Apr-25-2017, 06:43 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020