I am new to Python (and programming). In teaching myself I wrote a
small program that will pick random lottery numbers, I want to check for
duplicates and rerun the random function. But I am hitting a wall.
This is what I think should work, but I still get duplicates. TIA.
print "\n"
count = input("How many quick picks do you need? ")
print "\n"
num = 0
while count > 0:
num1 = randint(1,55)
num2 = randint(1,55)
while num2 == num1:
# looking for duplicates
num2 = randint(1,55)
num3 = randint(1,55)
while num3 == (num1 or num2):
# looking for duplicates
num3 = randint(1,55)
num4 = randint(1,55)
while num4 == (num1 or num2 or num3):
# looking for duplicates
num4 = randint(1,55)
num5 = randint(1,55)
while num5 == (num1 or num2 or num3 or num4):
# looking for duplicates
num5 = randint(1,55)
pb = randint(1,42)
count = count - 1
answer = [num1, num2, num3, num4, num5]
answer.sort()
num = num + 1
print "#",num, answer, "and for the powerball:", pb
print "\n"
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor