Advertisement
Dexter5292

Pre-release Private Student

Nov 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | None | 0 0
  1. __author__ = "Botha"
  2.  
  3. student_voted = []
  4. candidate_vote = []
  5. student_numbers = 0
  6.  
  7. def get_candidates():
  8.     global candidate_vote
  9.     username = "admin"
  10.     password = "d@G"
  11.     if (input("Please enter your user name")) == username:
  12.         if (input("Please enter your password:  ")) == password:
  13.             can_one = input("Please enter the name of candidate:  ")
  14.             can_two = input("Please enter the name of candidate:  ")
  15.             can_three = input("Please enter the name of candidate:  ")
  16.         else:
  17.             print("Incorrect Password")
  18.             get_candidates()
  19.     else:
  20.         print("Incorrect Username")
  21.         get_candidates()
  22.     candidate_vote = [[can_one, 0], [can_two, 0], [can_three, 0]]
  23.  
  24. def order(can):
  25.     if (can[0][1] >= can[1][1]) and (can[0][1] >= can[2][1]):
  26.         print("%s \t %s" % (can[0][0], can[0][1]))
  27.         if can[1][1] >= can[2][1]:
  28.             print("%s \t %s" % (can[1][0], can[1][1]))
  29.             print("%s \t %s" % (can[2][0], can[2][1]))
  30.         else:
  31.             print("%s \t %s" % (can[2][0], can[2][1]))
  32.             print("%s \t %s" % (can[1][0], can[1][1]))
  33.     elif (can[1][1] >= can[0][1]) and (can[1][1] >= can[2][1]):
  34.         print("%s \t %s" % (can[1][0], can[1][1]))
  35.         if can[0][1] >= can[2][1]:
  36.             print("%s \t %s" % (can[0][0], can[0][1]))
  37.             print("%s \t %s" % (can[2][0], can[2][1]))
  38.         else:
  39.             print("%s \t %s" % (can[2][0], can[2][1]))
  40.             print("%s \t %s" % (can[0][0], can[0][1]))
  41.     else:
  42.         print("%s \t %s" % (can[2][0], can[2][1]))
  43.         if can[0][1] >= can[1][1]:
  44.             print("%s \t %s" % (can[0][0], can[0][1]))
  45.             print("%s \t %s" % (can[1][0], can[1][1]))
  46.         else:
  47.             print("%s \t %s" % (can[1][0], can[1][1]))
  48.             print("%s \t %s" % (can[0][0], can[0][1]))
  49.  
  50. def percentages(can):
  51.     global student_numbers
  52.     if (can[0][1] >= can[1][1]) and (can[0][1] >= can[2][1]):
  53.         print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
  54.         if can[1][1] >= can[2][1]:
  55.             print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
  56.             print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
  57.         else:
  58.             print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
  59.             print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
  60.     elif (can[1][1] >= can[0][1]) and (can[1][1] >= can[2][1])
  61.         print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
  62.         if can[0][1] >= can[2][1]:
  63.             print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
  64.             print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
  65.         else:
  66.             print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
  67.             print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
  68.     else:
  69.         print("%s \t %s" % (can[2][0], (can[2][1]/student_numbers)*100))
  70.         if can[0][1] >= can[1][1]:
  71.             print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
  72.             print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
  73.         else:
  74.             print("%s \t %s" % (can[1][0], (can[1][1]/student_numbers)*100))
  75.             print("%s \t %s" % (can[0][0], (can[0][1]/student_numbers)*100))
  76.  
  77. def close(can, student_numbers):
  78.     order(can)
  79.     percentages(can)
  80.     print("The number of students that have voted is:  ", student_numbers)
  81.        
  82.  
  83. def get_vote():
  84.     global candidate_vote, student_numbers
  85.     student_numbers += 1
  86.     can = candidate_vote
  87.     print("Please choose a candidate to vote for:")
  88.     print("1. \t %s" % can[0][0])
  89.     print("2. \t %s" % can[1][0])
  90.     print("3. \t %s" % can[2][0])
  91.     vote = input()
  92.     if vote == '00000':
  93.         close(can, student_numbers)
  94.     elif vote == '1':
  95.         can[0][1] += 1
  96.         get_vote()
  97.        
  98.     elif vote == '2':
  99.         can[1][1] += 1
  100.         get_vote()
  101.     elif vote == '3':
  102.         can[2][1] += 1
  103.         get_vote()
  104.     else:
  105.         print("Invalid selection")
  106.         get_vote()
  107.    
  108.    
  109.  
  110. def validate_code(Code):
  111.     global student_voted
  112.     if (int(Code[0]) + int(Code[1])) - (int(Code[2]) + int(Code[3])) == int(Code[4]):
  113.         for i in student_voted:
  114.             if i == Code:
  115.                 print("You have already voted!")
  116.                 get_vote()
  117.         student_voted.append(Code)
  118.         return True
  119.  
  120. can_list = get_candidates()
  121. print("Please enter your student code:")
  122. code = input()
  123. if validate_code(code):
  124.     get_vote()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement