Online Voting System project in python with complete source code
In this article, i will show you how to create online voting system using python. It is very good project for beginners as its create programming logic and help to enhance the basic concepts of beginners. I will provide complete source code of this project ,so read the article carefully and implement the project step by step. In this mini project, i am using list data structure to store the lists of voters who want to cast their votes and leader who wants to participate in elections.
After completion of this project,learner will be able
- Understand how to use list data structure to manipulate data in list
- Understand how to search ,edit and delete elements of list
- Understand how to handle infinite loops
Basic concepts of Online voting system
This is a very good program, it works as Online Voter Machine. It allows voter to vote for any leader. It accepts candidates name for voting purpose. It accepts maximum 5 candidates name. Each user can vote only once using their voter id otherwise it generates an error message in the window. At the end it displays the result of the election with the number of votes of elected candidate(winner).
First, We will create leader list by using list data structure and store the names of 5 leaders who want to take part in election
# Task to register leader name who want to participate in election leader =  for i in range(1, 6): leader_name = input("Enter your leader name :") leader.append(leader_name) n = len(leader) if n < 5 : print("You have been successfully registerd") else : print("Maximum candidate have been enrolled")
Second, we will create list of voter who want to caste their vote
# Task to register candidate who want to caste their vote voter =  number = int(input("Enter total number of voter want to cast their vote :")) for i in range(1,number + 1): voter_id = int(input("Enter voter id number :")) voter.append(voter_id)
Then, we will create infinite loop to check whether voter list is empty or not. If voter list is empty then it will says “voting session is over” otherwise, it will calculate result
while True : if voter ==: print("Voting session is over") max = leader_1_votes if leader_2_votes > max: max = leader_2_votes percent = (leader_2_votes/num_of_voter)*100 print(leader,"has won","with",percent,"% votes") break elif leader_3_votes > max: max = leader_3_votes percent = (leader_3_votes/num_of_voter)*100 print(leader,"has won","with",percent,"% votes") break elif leader_4_votes > max: max = leader_4_votes percent = (leader_4_votes/num_of_voter)*100 print(leader,"has won","with",percent,"% votes") break elif leader_5_votes > max: max = leader_5_votes percent = (leader_5_votes/num_of_voter)*100 print(leader,"has won","with",percent,"% votes") break else : percent = (leader_1_votes/num_of_voter)*100 print(leader,"has won","with",percent,"% votes") break else : voter_id = int(input("Enter your voter-id no :")) if voter_id in voter: print("You are a voter ") voter.remove(voter_id) print("========================================================\n") print("Here are the list of leader name :") print(" 1.leader-1 : ",leader, "\n 2.leader-2 :",leader, "\n 3.leader-3 :",leader, "\n 4.leader-4 :",leader, "\n 5.leader-5 :",leader) vote = int(input("Cast your vote for leader 1 or leader2 or leader3 or leader4 or leader5 :\n" " Write only sr. no of leader(like 1 or 2 ) :\n")) print("===========================================================\n") if vote == 1: leader_1_votes+=1 print("Thank you for casting your vote ") elif vote == 2: leader_2_votes+=1 print("Thank you for casting your vote") elif vote == 3: leader_3_votes+=1 print("Thank you for casting your vote") elif vote == 4: leader_4_votes+=1 print("Thank you for casting your vote") elif vote == 5: leader_5_votes+=1 print("Thank you for casting your vote") else : print("Leader is not found \n PLease enter correct leader number") else : print("You have already voted or invalid voter id ")
Complete source code
This mini project is very good python program which enhances basic skill of learner. People and leaders both can use the application for voting as well for participating in the contest. At first, the application asked any user that they are Voters or a leader of any group. After that it takes respective operation. If the user is a leader, then the application asked the user to store their name, so that voters can nominate their leaders. But if the user is voter, then the application asked for Voter Id. The error handling is also perfect, in every wrong step, the application will show respective message, which makes the application more friendly. It also shows winner name and the number of votes he/she received.