From 9ba00fc72a4911d92a19e192694b559d7a8f2349 Mon Sep 17 00:00:00 2001 From: KimSongEun Date: Sat, 21 Nov 2020 03:45:01 +0900 Subject: [PATCH] app.py pull request --- app.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 92832af..c86ce0f 100644 --- a/app.py +++ b/app.py @@ -17,10 +17,41 @@ def lotto(): return jsonify(lotto) def select_numbers(select_amount:int): - ### 이곳을 같이 채워봐요 + lotto = [1, 2, 3, 4, 5, 6] - lotto = [1,2,3,4,5,6] + ### 이곳을 같이 채워봐요 + ## example 1 + lotto = [] + for i in range(select_amount): + + while True: + select_num = random.randint(1, 45) + + is_duplicated = False + for num in lotto: + if select_num == num: + is_duplicated = True + break + + if is_duplicated: + continue + lotto.append(select_num) + break + + ## example 2 + ''' + candidate_numbers = lotto_numbers[:] + lotto = [] + for i in range(select_amount): + select_num = candidate_numbers.pop(random.randrange(len(candidate_numbers))) + lotto.append(select_num) + ''' + + ## example 3 + ''' + lotto = random.sample(lotto_numbers, select_amount) + ''' return lotto