samedi 11 juillet 2020

random module error ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))

I'm trying to test my project and I have to call random module for that:

r = random.randint(0, len(x)-1)

random code is

 istart = _int(start)
    if istart != start:
        raise ValueError("non-integer arg 1 for randrange()")
    if stop is None:
        if istart > 0:
            return self._randbelow(istart)
        raise ValueError("empty range for randrange()")

    # stop argument supplied.
    istop = _int(stop)
    if istop != stop:
        raise ValueError("non-integer stop for randrange()")
    width = istop - istart
    if step == 1 and width > 0:
        return istart + self._randbelow(width)
    if step == 1:
        raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))

    # Non-unit step argument supplied.
    istep = _int(step)
    if istep != step:
        raise ValueError("non-integer step for randrange()")
    if istep > 0:
        n = (width + istep - 1) // istep
    elif istep < 0:
        n = (width + istep + 1) // istep
    else:
        raise ValueError("zero step for randrange()")

    if n <= 0:
        raise ValueError("empty range for randrange()")

    return istart + istep*self._randbelow(n)

I'm getting this error:

File "C:\Users\oguz_\OneDrive\Masaüstü\Lezyon\TestProje.py", line 156, in <module>
r = random.randint(0, len(x)-1)

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

File "C:\Users\oguz_\anaconda3\lib\random.py", line 200, 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