-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPolling App.py
More file actions
59 lines (49 loc) · 1.65 KB
/
Polling App.py
File metadata and controls
59 lines (49 loc) · 1.65 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
#Polling App
print("Welcome to the polling app.\n")
#prompt user input for cause of polling
topic = input("For what reason/ on which topic you want to have a poll: ")
password = input("Set a password for the poll: ")
num_voter = int(input("\nHow many voters you want to participate in your poll: "))
#create a voter database
voters = {}
yes = 0
no = 0
#ask all voters for their result
for i in range(num_voter):
user_name = input("\nEnter your name: ").title()
if user_name in voters:
print("You have already given your vote")
continue;
print("Hello! ", user_name, " today's topic of poll is ", topic)
vote = input("Your opinion for the poll(yes/no): ").upper()
voters[user_name] = vote
if vote == 'YES':
yes += 1
else:
no += 1
print("Thank you for your vote.")
voters[user_name] = vote
print("\npoll result(yes/no) : ", yes, "/", no)
result = 'YES'
per = 0
if yes > no:
result = 'YES'
per = round(yes/num_voter, 2)
elif no > yes:
result = 'NO'
per = round(no/num_voter, 2)
else:
result = 'TIE'
per = 50.0
print("People max opinion for ", topic, " is ", result, " with percentage ", per)
#ask creater for shoing all result of all people
choose = input("Do you want to see all voters result: ").lower()
if choose == 'yes':
pas = input("Password of poll: ")
if pas == password:
for key, value in voters.items():
print(key, "\t", value)
else:
print("paswword is wrong!, Sorry I acnt let you to see the poll result")
else:
print("Thank you. Hope you find your answer:-).")