vendredi 12 octobre 2018

Using max() to find highest in a list, and if they tie, choose only one

I'm making a voting software, and having some problems. Here is a sample:

import random


One = "Test"
Two = "Testy"
Three = "Testyy"
Four = "Testyyy"
Five = "Testyyyy"
Six = "Testyyyyy"

running = {One: 0, Two: 0, Three: 0, Four: 0, Five: 0, Six: 0}


for voter in running:
    vote = random.choice(running)

    running[vote] += 1

winner = max(running)

I want to make it so if two candidates tie for the win, it will randomly select one of them as the winner. Is there any way to do this?




Aucun commentaire:

Enregistrer un commentaire