Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = "Botha"
- student_voted = []
- candidate_vote = []
- student_numbers = 0
- def get_candidates():
- global candidate_vote
- username = "admin"
- password = "d@G"
- if (input("Please enter your user name")) == username:
- if (input("Please enter your password: ")) == password:
- can_one = input("Please enter the name of candidate: ")
- can_two = input("Please enter the name of candidate: ")
- can_three = input("Please enter the name of candidate: ")
- else:
- print("Incorrect Password")
- get_candidates()
- else:
- print("Incorrect Username")
- get_candidates()
- candidate_vote = [[can_one, 0], [can_two, 0], [can_three, 0]]
- def order(can):
- if (can[0][1] >= can[1][1]) and (can[0][1] >= can[2][1]):
- print("%s \t %s" % (can[0][0], can[0][1]))
- if can[1][1] >= can[2][1]:
- print("%s \t %s" % (can[1][0], can[1][1]))
- print("%s \t %s" % (can[2][0], can[2][1]))
- else:
- print("%s \t %s" % (can[2][0], can[2][1]))
- print("%s \t %s" % (can[1][0], can[1][1]))
- elif (can[1][1] >= can[0][1]) and (can[1][1] >= can[2][1]):
- print("%s \t %s" % (can[1][0], can[1][1]))
- if can[0][1] >= can[2][1]:
- print("%s \t %s" % (can[0][0], can[0][1]))
- print("%s \t %s" % (can[2][0], can[2][1]))
- else:
- print("%s \t %s" % (can[2][0], can[2][1]))
- print("%s \t %s" % (can[0][0], can[0][1]))
- else:
- print("%s \t %s" % (can[2][0], can[2][1]))
- if can[0][1] >= can[1][1]:
- print("%s \t %s" % (can[0][0], can[0][1]))
- print("%s \t %s" % (can[1][0], can[1][1]))
- else:
- print("%s \t %s" % (can[1][0], can[1][1]))
- print("%s \t %s" % (can[0][0], can[0][1]))
- def percentages(can):
- global student_numbers
- if (can[0][1] >= can[1][1]) and (can[0][1] >= can[2][1]):
- print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
- if can[1][1] >= can[2][1]:
- print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
- print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
- else:
- print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
- print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
- elif (can[1][1] >= can[0][1]) and (can[1][1] >= can[2][1])
- print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
- if can[0][1] >= can[2][1]:
- print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
- print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
- else:
- print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
- print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
- else:
- print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
- if can[0][1] >= can[1][1]:
- print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
- print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
- else:
- print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
- print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
- def close(can, student_numbers):
- order(can)
- percentages(can)
- print("The number of students that have voted is: ", student_numbers)
- def get_vote():
- global candidate_vote, student_numbers
- student_numbers += 1
- can = candidate_vote
- print("Please choose a candidate to vote for:")
- print("1. \t %s" % can[0][0])
- print("2. \t %s" % can[1][0])
- print("3. \t %s" % can[2][0])
- vote = input()
- if vote == '00000':
- close(can, student_numbers)
- elif vote == '1':
- can[0][1] += 1
- get_vote()
- elif vote == '2':
- can[1][1] += 1
- get_vote()
- elif vote == '3':
- can[2][1] += 1
- get_vote()
- else:
- print("Invalid selection")
- get_vote()
- def validate_code(Code):
- global student_voted
- if (int(Code[0]) + int(Code[1])) - (int(Code[2]) + int(Code[3])) == int(Code[4]):
- for i in student_voted:
- if i == Code:
- print("You have already voted!")
- get_vote()
- student_voted.append(Code)
- return True
- can_list = get_candidates()
- print("Please enter your student code:")
- code = input()
- if validate_code(code):
- get_vote()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement