mardi 26 novembre 2019

Is there a way of saying "if anything == anything"? (Python)

sample code:

import random

x = random.randint(1, 101)
y = random.randint(1, 101)
z = random.randint(1, 101)

print(x, y, z)

Now, is there an easier way of saying

while x == y or x == z or y == z:
    x = random.randint(1, 101)
    y = random.randint(1, 101)
    z = random.randint(1, 101)

Because the more variables you have, the longer that while statement goes and the uglier and more frustrating it gets if you forget something.

Something like: If any variable is equal to any other one: reroll.

Thanks!




Aucun commentaire:

Enregistrer un commentaire