Python作业|代做Assignment – python assignment

Python作业|代做Assignment – 这是一个简单的DSA相关的利用python进行处理的问题

Regarding the assignment for DSA, I have doubts on the report for List by Margin (on page 2).

1. Which file should I refer to?

They will need to work with the following files, but I suggest they start with one of the

state files before doing all the states together.

National list of candidates [CSV 58 KB | TAB 58 KB]

First preferences by candidate by polling place – NSW [CSV 2.1 MB | TAB 2.1 MB]

First preferences by candidate by polling place – VIC [CSV 1.2 MB | TAB 1.2 MB]

First preferences by candidate by polling place – QLD [CSV 1.1 MB | TAB 1.1 MB]

First preferences by candidate by polling place – WA [CSV 729 KB | TAB 729 KB]

First preferences by candidate by polling place – SA [CSV 479 KB | TAB 479 KB]

First preferences by candidate by polling place – TAS [CSV 159 KB | TAB 159 KB]

First preferences by candidate by polling place – ACT [CSV 44 KB | TAB 44 KB]

First preferences by candidate by polling place – NT [CSV 44 KB | TAB 44 KB]

2. How to know the list of all marginal seats within a threshold from the file?

3. Can you give me an example?

This is some Python code to explore the file and get the margin for a particular seat in

WA – it may be useful as pseudocode if you want to share it with the students:

# Testing assignment DSA Sem2 2018

fileobj = open("HouseStateFirstPrefsByPollingPlaceDownload- 20499 – WA.csv","r")

lines = fileobj.readlines()

print(lines[ 0 ].split(‘,’))

print(lines[ 1 ].split(‘,’))

print(lines[ 2 ].split(‘,’))

party = "ALP"

division = "235"

votesfor = 0

votesagainst = 0

for line in lines[ 2 :]:

sline = line.split(‘,’)

thisdiv = sline[ 1 ]

thisparty = sline[ 11 ]

if division == thisdiv:

if party == thisparty:

print(party+" votes:", sline[ 13 ])

votesfor = votesfor + int(sline[ 13 ])

else:

print("Other votes:", sline[ 13 ])

votesagainst = votesagainst + int(sline[ 13 ])

print("\nTotal for : ", votesfor)

print("Total against : ", votesagainst)

print("Percent : " , (votesfor / (votesfor+votesagainst))* 100 , "%")

print("Margin : " , (votesfor / (votesfor+votesagainst))* 100 – 50 )

The output is:

<190 lines of results before this>

ALP votes: 1056

Other votes: 61

Other votes: 228

Other votes: 430

Other votes: 112

Other votes: 58

ALP votes: 476

Other votes: 41

Other votes: 152

Other votes: 432

Other votes: 51

Total for : 32556

Total against : 37345

Percent : 46.57444099512168 %

Margin : – 3.

So the margin is -3.4%, within the default threshold of +/- 6%.

发表评论

电子邮件地址不会被公开。 必填项已用*标注