-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoting_system.py
More file actions
90 lines (75 loc) · 2.18 KB
/
Copy pathvoting_system.py
File metadata and controls
90 lines (75 loc) · 2.18 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
candidates = []
voters = []
votes = {}
voted_voters = []
def register_candidate():
name = input(" Enter candidate Name:");
age = int(input(" Enter candidate Age:"));
party = input(" Enter candidate political party:");
relatioshipStatus = input(" Enter candidate relatioship status:").lower();
if(relatioshipStatus == "married" and age >= 18):
candidates.append(name);
votes[name] = 0;
print(name + " has been successfuly registered");
else:
print("candidate doesn't meet the requirement");
def register_voters():
name = input(" Enter your Name:");
age = int(input(" Enter your Age:"));
nationality = input("Are you a nigerian:").lower();
if(age >= 18 and nationality == "yes"):
voters.append(name);
print(name + " has been successfuly registered and eligible to vote");
else:
print("you are not eligible");
def vote_process():
print("Voting ")
name = input("Enter your name: ")
if name in voters and name not in voted_voters:
print("Candidates:")
for candidate in candidates:
print(f" {candidate}")
choice = input("Enter the name of the candidate you want to vote for: ")
if choice in candidates:
votes[choice] += 1
voted_voters.append(name);
print("Vote cast successfully");
else:
print("Invalid candidate.");
elif name in voted_voters:
print("you have already voted");
else:
print("You are not a registered voter");
def count_votes():
print("Counting Votes ")
for candidate, count in votes.items():
print(f"{candidate}: {count} vote(s)")
print()
def main():
while True:
print(" Voting System Menu");
print("1. Register Candidate");
print("2. Register Voter");
print("3. Vote");
print("4. Count Votes");
print("0. Exit");
option = int(input("Select any option: "));
match(option):
case 1:
print("Register Candidate");
register_candidate();
case 2:
print("Register Voter");
register_voters();
case 3:
print("Vote");
vote_process();
case 4:
print("Count Votes");
count_votes();
case 0:
print("bye bye");
break;
case _:
print("Invalid choice. Try again");
main()