def prompt_vote_poll(): poll_id = int(input("Enter poll would you like to vote on: ")) _print_poll_options(Poll.get(poll_id).options) option_id = int(input("Enter option you'd like to vote for: ")) username = input("Enter the username you'd like to vote as: ") Option.get(option_id).vote(username)
def randomize_poll_winner(): poll_id = int(input("Enter poll you'd like to pick a winner for: ")) _print_poll_options(Poll.get(poll_id).options) option_id = int( input( "Enter which is the winning option, we'll pick a random winner from voters: " )) votes = Option.get(option_id).get_votes winner = random.choice(votes) print(f"The randomly selected winner is {winner[0]}.")
def show_poll_votes(): poll_id = int(input("Enter poll you would like to see votes for: ")) options = Poll.get(poll_id).options votes = [len(option.get_votes) for option in options] total_votes = sum(votes) try: for option, vote in zip(options, votes): percentage = vote / total_votes * 100.0 print( f"{option.option_text} got {vote} votes ({percentage:.2f}% of total)" ) except ZeroDivisionError: print("No votes yet cast for this poll.")