Generate three different random numbers
You can use random.sample
to get any amount of unique 'random' items from an iterable- there is no need to use nested loops:
>>> option1, option2, option3 = random.sample(range(1, 4), 3)
>>> option1, option2, option3
(3, 1, 2)
The bug in your code is that if option1
and option2
are different, the first while
won't be entered, and you won't examine if any of them are equal to option3
.