Input:
import random
I = 0
z = []
while I < 6:
y = random. Choices(range(1,50))
if y in z:
break
z += y
I += 1
print(z)
Output: [8, 26, 8, 44, 31, 22]
I'm trying to make a Lotto numbers generator but I can't make the code to generate 6 numbers that do not repeat. As you can see in the Output 8 is repeating.
I'm not clear why in the If statement the code does not check if the random y variable is already in the z list.
continue
instead ofbreak
to continue the loop from the top again.choices
returns a list. Checking whether a list exists in a list will (in your case) always be false.