Exemplo n.º 1
0
def randomize_poll_winner():
    poll_id = int(input("Enter poll you'd like to pick a winner for: "))

    options = Poll.get(poll_id).options
    _print_poll_options(options)

    option_id = int(input("Enter which is the winning option, we'll pick a random winner from voters: "))
    votes = Option.get(option_id).votes    
    winner = random.choice(votes)
    print(f"The randomly selected winner is {winner[0]}.")
Exemplo n.º 2
0
def prompt_vote_poll():
    poll_id = int(input("Enter poll would you like to vote on: "))
    poll = Poll.get(poll_id)
    options = poll.options
    _print_poll_options(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)
Exemplo n.º 3
0
def show_poll_votes():
    # get input on which poll's info to see
    poll_id = int(input("Enter poll you would like to see votes for: "))

    # get poll of interest
    poll = Poll.get(poll_id)
    # get options for that poll
    options = poll.options
    # get number of votes per option
    votes_per_option = [len(option.votes) for option in options]
    # calculate the total number of votes from values in list
    total_votes = sum(votes_per_option)

    # iterate over options and according votes and print out info
    try:
        for option, votes in zip(options, votes_per_option):
            percentage = votes/total_votes * 100
            print(f"{option.text}: got {votes} votes ({percentage}% of total votes)")
    except ZeroDivisionError:
        print("No votes were casted for this poll yet.")