본문 바로가기
python

[python] random으로 로또 번호 추첨하기

by 바디스 2020. 7. 22.
  • 랜덤으로 6자리의 숫자를 출력한다.
  • 겹치는 숫자가 없도록 한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import random
 
rotto = []
num = random.randint(1,46)
rotto.append(num)
while(1):
    num = random.randint(1,46)
    i=0
    while(1):
        if(num==rotto[i]):
            break
        else:
            i+=1
        if(i == len(rotto)):
            rotto.append(num)
            break
    if(len(rotto)==6):
        break
 
print(rotto)
cs

 

댓글