MapleStory Finger Point

๐Ÿ’Ž Python/Python_Code

๋กœ๋˜ ๋ฒˆํ˜ธ ์ถ”์ฒจ ํ”„๋กœ๊ทธ๋žจ - ํŒŒ์ด์ฌ for Beginner (2ํŒ) // self study 9-2

HYEJU01 2024. 3. 30. 03:34

 

๋žœ๋คํ•จ์ˆ˜๊ฐ’์„ ๋งŒ๋“ค์–ด์ฃผ๋Š” 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='')