mardi 12 janvier 2021

Using random.randint() returns error for my script

The part of the code showing the error:

        houseOriginalLen = len(houseList)
        house = houseList[0][3]
        while len(houseList) > 0:
            person1 = houseList[random.randint(0,len(houseList)-1)]
            houseList.remove(person1)
            person2 = houseList[random.randint(0,len(houseList)-1)]
            houseList.remove(person2)
            mediator = mediators[random.randint(0, len(mediators)-1)]
            mediators.remove(mediator)
            fixture = "{} vs {}".format(person1[1], person2[1])
            if len(houseList) == houseOriginalLen:
                print("{} fixtures:".format(house))
            print("{} observed by {} in Zoom Room: {}".format(fixture, mediator[1],mediator[2]))
            writer.writerow([fixture, house, mediator[1],mediator[2]])
        return "\n"```

The error:

  File "C:\Users\arush\OneDrive - Pathways Group of Schools\Python\PCT21\fixture maker.py", line 133, in <module>
    makeFixtures(registeredPeople, observingPeople, fixtures)

  File "C:\Users\arush\OneDrive - Pathways Group of Schools\Python\PCT21\fixture maker.py", line 127, in makeFixtures
    printFixtures(firePlayers)

  File "C:\Users\arush\OneDrive - Pathways Group of Schools\Python\PCT21\fixture maker.py", line 114, in printFixtures
    person2 = houseList[random.randint(0,len(houseList)-1)]

  File "C:\Users\arush\anaconda3\lib\random.py", line 248, in randint
    return self.randrange(a, b+1)

  File "C:\Users\arush\anaconda3\lib\random.py", line 226, in randrange
    raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))

ValueError: empty range for randrange() (0, 0, 0)```



Aucun commentaire:

Enregistrer un commentaire