Advertisement
skip420

vote_VoterID

Jun 7th, 2022
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. # python3 vote_VoterID.py
  2.  
  3.  
  4. # Welcome massage.
  5. print("Welcome To The Voting Center")
  6.  
  7. # Nominee info. You can also add more than 2 nominee.
  8. nominee1 = input("Enter the nominee 1 name : ")
  9. nominee2 = input("Enter the nominee 2 name : ")
  10.  
  11. # Initial value of there vote must be 0 for both.
  12. nominee1Votes = 0
  13. nominee2Votes = 0
  14.  
  15. # Voter id to detect fake voters.
  16. voterId = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  17. numberOfVoters = len(voterId)
  18.  
  19. # main loop( we are using while loop).
  20. while True:
  21.  
  22.     # To check voter list is completed or become empty.
  23.     if voterId == []:
  24.         print("Voting session is over !!!")
  25.         if nominee1Votes > nominee2Votes:
  26.             # To calculate the percentage.
  27.             percent = (nominee1Votes/numberOfVoters)*100
  28.             print(f"{nominee1} has won the election with {percent} %.")
  29.             # to break the loop and exit the program.
  30.             break
  31.  
  32.         elif nominee2Votes > nominee1Votes:
  33.             # To calculate the percentage.
  34.             percent = (nominee2Votes/numberOfVoters)*100
  35.             print(f"{nominee2} has won the election with {percent} %.")
  36.             # to break the loop and exit the program.
  37.             break
  38.  
  39.         # if they got equal votes.
  40.         else:
  41.             print("Both have got equal number of votes !! Heigher authority will decide the final result, Thankyou !!")
  42.             # to break the loop and exit the program.
  43.             break
  44.    
  45.     # For taking voter id
  46.     voterIdDetection = int(input("Enter your voter id : "))
  47.     # for detecting fake voters vs real voters.
  48.     if voterIdDetection in voterId:
  49.         print("You are a genuine voter ")
  50.         # we will remove voterId so that same voter can't vote again.
  51.         voterId.remove(voterIdDetection)
  52.         print("______________________________________")
  53.         print(f"To give a vote to {nominee1} Press 1 : ")
  54.         print(f"To give a vote to {nominee2} Press 2 : ")
  55.         print("______________________________________")
  56.         # checking voter votes whom.
  57.         vote = int(input("Enter your precious vote : "))
  58.         if vote == 1:
  59.             nominee1Votes += 1
  60.             print(f"{nominee1}, Thanks you to give me your important vote !! ")
  61.         elif vote == 2:
  62.             nominee2Votes += 1
  63.             print(f"{nominee2}, Thanks you to give me your important vote !! ")
  64.         elif vote > 2:
  65.             print("Check your presed key is it right or wrong !!")
  66.         else:
  67.             print("You are not a genuine voter OR You have already voted ")
  68.     else:
  69.         print("You are not a genuine voter OR You have entered wrong Voter ID , else you already give your precious vote.")
  70.  
  71. # Goodbye massage.
  72. print(" Thanks for giving your valuable time and vote.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement