samedi 23 février 2019

python random lottery number generator game

I have to make a game where like the lottery my program generates 5 random numbers from a list of numbers 1-50 and one additional number from a list of numbers 1-20 and combines them into a final list that reads eg: (20, 26, 49, 01, 11, + 06) where two numbers are never repeated like (22, 11, 34, 44, 01, + 22) <--- this is what I don't want

attached below is the code I have written yet how do I make it so two numbers or more are never repeated and to add the + into my list without the "" signs

input: import random

a = list(range(1,51))
b = random.randint(1, 20)

temp = []

for i in range(5):
  random.shuffle(a) 
  temp.append(random.choice(a[:5])) 
temp.append('+')
temp.append(b)

print(temp)

output:

[14, 12, 3, 16, 23, '+', 9]




Aucun commentaire:

Enregistrer un commentaire