Coders Packet

Voting System in console using Python

By Anurag Singh

Hi, Today we are going to build a voting system by using one of the best high-level programming languages, python.

First of all, we have to discuss some logic or I must say roadmap on which our voting system will be going to build.

Now, I will be going to give you a brief explanation of what we are going to build. We built a voting system in a prompted manner. In which we have 2 or more nominees. Then after it will ask the user to enter the name of the nominee, after that it will ask the user to enter a unique code or something like ID. So, that we can manage the fake voters and our result will be free from partiality. At last, we will show the result of voting in form of a percentage (when I am making this virtual pet it was python 3.9).

Let's build our voting system with the help of python.

First of all, I'll write out something called pseudocode, which is essentially what is the logical steps of building out a program. It is necessarily coded itself but we need to build pieces of the program and eventually put them all together.

vote 1

These are some key points for making our voting system.

Now we are going to make the first version of our voting system.

vote 2

In this version, we are going to add 2 nominees and set their initial value of voters 0, so that later we can increase voters' value as they got a vote. We Also add voter ID so that we can filter the fake voters.

If we run this stack of code, our code will give the following output.

[

Welcome To The Voting Center
Enter the nominee 1 name: xyz
Enter the nominee 2 name: qwerty
xyz
qwerty
10
Thanks for giving your valuable time and vote.

]

Note:-  I am using square brackets [ ] to bind the output

vote 3

In this version, we make a continuous while loop to take inputs by the user continuously, after that we ask the user to give their unique ID, and if ID matches with the system then he or she will be eligible for voting.

If we run this stack of code, our code will give the following output.

[

Welcome To The Voting Center
Enter the nominee 1 name: xyz
Enter the nominee 2 name: qwerty
Enter your voter id: 2
You are a genuine voter
______________________________________
To give a vote to xyz Press 1 :
To give a vote to qwerty Press 2 :
______________________________________
Enter your voter id: 2
Enter your voter id :

]

vote 4

In this version, we are going to handle that voter votes whom, so that we can compare their votes and give the results. We also handle various scenarios like, if a voter can only vote once and fake voters will not able to vote, etc.

vote 5.1

This is our final version of making a voting system by using python.

In this version, we are going to show the result of the voting session. We also going to handle, what happens if both got the same votes and we also break our continuous while loop that our program will not show any error.

_________________________________________________________________________________________________________________________

Now finally our voting system is ready to use. 

List of some additional changes:-

1. You can also add more nominees to this voting system.

2. You can also add more than 10 people to this program by increasing voter ID.

_________________________________________________________________________________________________________________________

Enjoy the Voting System and if you are eligible, do not forget to take part in all voting sessions which are held by our government. 

Thanks!

 

Download Complete Code

Comments

  • Agbaje Franklin :

    its awesome.

    quiet explanatory

  • Reply to this comment