본문 바로가기

파이썬

(Python) 로또 list 에 담아 뽑기

import random

count = 0
arr = []

num = 0

while count !=6:
    num = random.randint(1,46)

    if num not in arr:
        arr.append(num)
        count+=1
arr.sort()
print(arr)

출력 값 : [7, 9, 10, 18, 28, 34]

 

'파이썬' 카테고리의 다른 글

(Python) Web site 경로를 따라가 데이터 찾기  (0) 2020.11.07
(Python) - BeautifulSoup  (0) 2020.11.05
(Python) 사칙연산  (0) 2020.10.13