-1
Good evening! I am very beginner in Python and I am trying to implement a function that generates numbers to be used in mega sena games. However, when executing the said function it returns me the following:
[54, 38, 32, 54, 38, 28]
Note that the return of the function is formed by a list containing some repeated values.
I would like to avoid repeated numbers. How can I proceed?
Code
from random import randint
def gerar_seis_numeros():
numeros = []
for i in range(6):
numeros.append(randint(0, 60))
return numeros
def completar():
return randint(0, 60)
n = gerar_seis_numeros()
for i in range(6):
if n[i] != n[i]:
print(completar())
Luiz Machado, first of all welcome to the platform. Second, if you want to generate draws of numbers to be used as guesses of Mega Sena games, use the method
sample
libraryrandom
. Read also How-to No Questions Manual. Hug and always come back.– Solkarped