-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyPoll
More file actions
66 lines (49 loc) · 1.5 KB
/
PyPoll
File metadata and controls
66 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import csv
voterID = 0
vote_total = 0
net_list = []
date_list = []
budget_csv = os.path.join("..", "Downloads", "03-Python_Homework_2.csv")
with open(budget_csv, newline="") as csvfile:
csvreader = csv.DictReader(csvfile, delimiter=",")
for row in csvreader:
print(row)
def average(numbers):
length = len(numbers)
total = 0.0
for number in numbers:
total += number
return total / length
# Test your function with the following:
print(average([1, 5, 9]))
print(average(range(11)))
# Define the funtion and have it accept the "poll data" as its sole parameter
def candidate_votes(poll_data):
khan_votes = int(poll_data[0])
correy_votes = int(poll_data[0])
li_votes = int(poll_data[0])
otooley_votes = int(poll_data[0])
winner = str(max([1]))
# Read the header row first (skip this part if there is no header)
csvfile = next(csvreader)
first_row = next(csvreader)
vote_total = int(first_row[0]) + vote_total
previous_row = int(first_row[0])
voterID += 1
# Read through each row of data after the header
for row in csvreader:
voterID += 1
vote_total = vote_total + int(row[0])
net_change = int(row[0])-previous_row
previous_row = int(row[0])
net_list.append(net_change)
date_list.append(row[0])
print('Election Results')
print('------------------------')
print(vote_total)
print(khan_votes)
print(correy_votes)
print(li_votes)
print(otooley_votes)
print(winner)