How to Make a Poll in Python

In this tutorial, you’ll discover a simple way to create an interactive poll using Python. The process utilizes Python’s built-in libraries to input data from the user and present it in a clear and organized manner. With this knowledge, you’ll be ready to collect and respond to user input in your own Python projects!

Step 1: Import Python Libraries

For this example, we only need one library: collections. This built-in Python library will help us tally the votes of our poll. Add the following line at the top of your Python file:

Step 2: Create the Poll

Now, we need to define the poll. Here is a simple poll question with two possible responses: ‘Yes’ and ‘No’.

Step 3: Gather User Responses

Next, we need to collect responses from users. We can use Python’s built-in function input() for this task. The loop will continue until a user inputs an ‘end’ response.

Step 4: Count the Votes

Lastly, we will use collections.Counter(), which counts the frequency of each item in our list:

Full Code

Conclusion

Creating a poll in Python is simple and straightforward. With the use of Python’s built-in libraries and functions, we’ve made an interactive poll that collects and records user input and then presents a tally of the results.

Once you’ve grasped these basic concepts, you can easily modify this to suit your needs, adding more poll options, or even creating multiple polls. Happy coding!