Question 1: CSV|Chart

Your church youth group is hosting a “Favorite Bible Character” Voting Contest to inspire young members to learn more about biblical figures. Participants can vote for one of four beloved Bible characters: David, Esther, Moses, or Ruth.

The aim is to make the voting process fair and transparent while ensuring everyone can view the results in a visually engaging way.


Task:

Write a Python program using Streamlit to create a voting app.

  1. Menu options:
    Create a sidebar with two options:

    • “Cast Your Vote” for participants to vote.
    • “View Results” to display the current standings.
  2. Voting process:

    • Ask the user for their name and their favorite Bible character.
    • If the participant has already voted, display a message to prevent duplicate votes.
    • Save valid votes to a CSV file.
  3. Display results:

    • Count votes for each character.
    • Show the results as a table and visualize them as a bar chart using Plotly.

Steps to Solve:

  1. Create the app:

    • Use Streamlit to build the app interface.
    • Initialize or load a CSV file (bible_votes.csv) to store the voting data.
  2. Design the voting menu:

    • Add input fields for the participant’s name and character selection.
    • Check for duplicate votes by verifying if the name already exists in the CSV file.
    • Save new votes to the CSV file.
  3. Design the results menu:

    • Count the votes for each Bible character using pandas.
    • Display the results in a table.
    • Use Plotly to create a bar chart to visualize the results.
  4. Handle exceptions:

    • Display a warning if no votes have been cast yet.
Write what you are looking for, and press enter to begin your search!