๋๋คํจ์๊ฐ์ ๋ง๋ค์ด์ฃผ๋ getNumber ํจ์๋ฅผ ๋ง๋ ๋ค.
๋ก๋ ๋ฒํธ num , ๋ฃ์ lotto ๋ฆฌ์คํธ ์ด๊ธฐํ,
๋ฌดํ๋ฃจํ๋ก ๋๋ค ์ซ์๋ฅผ ์์ฑํด์ค๋ค.
์กฐ๊ฑด๋ฌธ : ๋ฆฌ์คํธ์ num์ซ์๊ฐ ์๋์ง ํ์ธ ! => ์์ผ๋ฉด num ๊ฐ์ ์ถ๊ฐํ๋ค.
์กฐ๊ฑด๋ฌธ : ๋ฆฌ์คํธ ๊ธธ์ด๊ฐ 6๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ผ๋ฉด ๋ฉ์ถ๋ค
๋ก๋๋ฒํธ๋ฅผ ๋ณด๊ธฐ ์ข๊ฒ ์ ๋ ฌํด์ฃผ๊ณ 6์๋ฆฌ๋ฅผ ์ถ๋ ฅํด์ฃผ๋ฉด ๋.
import random
def getNumber():
return random.randrange(1,46)
lotto = []
num = 0
print("๋ก๋ ์ถ์ฒจ์ ์์ํฉ๋๋ค!!\n")
while True:
num = getNumber()
if lotto.count(num) == 0:
lotto.append(num)
if len(lotto) >= 6 :
break
print("๋ก๋ ๋ฒํธ = >", end='')
lotto.sort()
for i in range(0,6):
print("%d " %lotto[i], end='')