jeudi 1 décembre 2022

How do I set a variable with the value being a random range, with variables set to have a random range?

I have this variable called "number" with the range being the variables "a" and "b". These range variables are ranges themselves.

from random import *

a = randint(1, 99)
b = randint(2, 100)

number = randint(a, b)
print(number)

When I try to enter this code, I occasionally receive an integer or get this error:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    number = randint(a, b)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/random.py", line 248, in randint
    return self.randrange(a, b+1)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/random.py", line 226, in randrange
    raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (17, 6, -11)



Aucun commentaire:

Enregistrer un commentaire