-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyPoll-main.py
More file actions
70 lines (43 loc) · 1.57 KB
/
PyPoll-main.py
File metadata and controls
70 lines (43 loc) · 1.57 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
67
68
import os
import csv
candidates = []
total_candidates = []
candidate_percent = []
candidate_total = []
summaries = []
csv_path1 = os.path.join("election_data_1.csv")
with open(csv_path1, "r", newline = "") as csv_data1:
datafile1 = csv.reader(csv_data1, delimiter = ",")
next(datafile1)
rows = 0
for row in datafile1:
total_candidates.append(row[2])
rows += 1
# sorted list of total_candidates
sorted_candidates = sorted(total_candidates)
for i in range(rows):
if sorted_candidates[i - 1] != sorted_candidates[i]:
candidates.append(sorted_candidates[i])
print(" Election Results")
print("-------------------------------------")
print("Total Votes:", rows)
print("-------------------------------------")
for j in range(len(candidates)):
candidate_count = 0
for k in range(len(sorted_candidates)):
if candidates[j] == sorted_candidates[k]:
candidate_count += 1
candidate_percent.append(round(candidate_count / rows * 100, 1))
candidate_total.append(candidate_count)
ziped_file = zip(candidates, candidate_percent, candidate_total)
for row in ziped_file:
print(row[0] + ":", str(row[1]) + "%", "(" + str(row[2]) + ")")
summary = (row[0] + ": ", str(row[1]) + "%", " (" + str(row[2]) + ")")
summaries.append(summary)
for k in range(len(candidate_percent)):
if candidate_total[k] > candidate_total[k - 1]:
the_winner = candidates[k]
print("----------------------------------------" )
print("Winner:", the_winner)
print("-----------------------------------------")
print(" ")