반응형
다음 코드는 파이썬을 이용해서 로또 복권번호를 자동으로 생성하는 코드입니다.
실행하면 "로또복권: 몇 장을 발행할까요? "라고 묻습니다.
발행할 복권 매수를 입력하면 1~45사이의 자동 번호를 6개씩 생성해줍니다.
import random
def generate_lottery_numbers(num_tickets, num_numbers):
lottery_numbers = []
for _ in range(num_tickets):
numbers = random.sample(range(1, 46), num_numbers)
lottery_numbers.append(numbers)
return lottery_numbers
def main():
num_tickets = int(input("로또복권: 몇 장을 발행할까요? "))
lottery_numbers = generate_lottery_numbers(num_tickets, 6)
print("[발행된 자동 복권 번호]")
print("--------------------------");
for numbers in lottery_numbers:
numbers.sort() # Sort the numbers in ascending order
print(numbers)
print("--------------------------");
if __name__ == '__main__':
main()
(실행 화면)
100개를 생성해 봤습니다. 아마 이 중에서 1등 번호도 나올겁니다. 아니면 이미 나왔거나...?
로또복권: 몇 장을 발행할까요? 100 [발행된 자동 복권 번호] -------------------------- [8, 15, 29, 35, 36, 37] [2, 6, 19, 24, 32, 36] [3, 16, 17, 34, 35, 44] [8, 10, 11, 15, 35, 39] [10, 12, 17, 27, 30, 37] [3, 8, 23, 24, 30, 42] [12, 16, 29, 31, 32, 45] [1, 2, 5, 6, 20, 43] [5, 7, 13, 21, 22, 36] [5, 17, 31, 32, 36, 44] [22, 31, 34, 37, 38, 39] [15, 17, 23, 25, 36, 45] [7, 12, 14, 20, 28, 42] [5, 7, 8, 18, 27, 38] [2, 6, 21, 26, 35, 44] [20, 21, 24, 35, 38, 41] [17, 20, 26, 35, 42, 44] [5, 13, 15, 17, 21, 43] [6, 11, 12, 20, 39, 44] [9, 10, 17, 21, 24, 25] [5, 7, 17, 21, 25, 31] [10, 14, 20, 30, 35, 41] [5, 10, 19, 20, 26, 32] [2, 4, 20, 31, 33, 41] [3, 8, 13, 34, 38, 45] [4, 18, 38, 40, 42, 45] [2, 3, 18, 28, 42, 44] [27, 31, 36, 40, 41, 43] [1, 7, 22, 25, 29, 30] [6, 10, 23, 28, 36, 37] [13, 17, 19, 24, 28, 36] [2, 5, 9, 30, 34, 36] [2, 8, 11, 21, 22, 32] [8, 13, 25, 31, 40, 44] [6, 10, 11, 12, 20, 33] [3, 31, 34, 38, 41, 42] [2, 3, 12, 15, 22, 44] [3, 5, 12, 25, 34, 43] [4, 8, 14, 20, 37, 41] [14, 17, 18, 33, 36, 39] [6, 7, 12, 14, 22, 44] [4, 5, 10, 25, 26, 33] [3, 5, 19, 22, 26, 43] [9, 11, 20, 26, 30, 38] [18, 22, 28, 35, 37, 44] [2, 6, 7, 9, 12, 36] [18, 20, 23, 26, 29, 41] [13, 21, 28, 33, 34, 43] [2, 5, 16, 29, 32, 37] [5, 19, 20, 28, 36, 45] [2, 13, 22, 29, 33, 44] [6, 20, 23, 29, 32, 42] [1, 13, 21, 35, 40, 42] [5, 18, 26, 34, 37, 44] [16, 26, 27, 35, 39, 44] [16, 20, 21, 30, 31, 43] [8, 9, 18, 26, 38, 44] [4, 11, 17, 27, 28, 34] [11, 20, 26, 35, 39, 41] [6, 18, 21, 24, 32, 45] [9, 14, 29, 34, 35, 38] [3, 9, 10, 17, 24, 39] [9, 14, 18, 21, 23, 29] [10, 14, 24, 27, 36, 37] [10, 12, 18, 31, 35, 39] [12, 14, 22, 24, 28, 34] [4, 16, 23, 28, 37, 41] [2, 12, 15, 22, 41, 44] [10, 11, 12, 13, 26, 37] [4, 7, 12, 31, 33, 45] [4, 5, 9, 12, 28, 30] [4, 12, 25, 29, 32, 40] [10, 14, 15, 19, 33, 40] [9, 13, 19, 28, 30, 34] [1, 7, 12, 21, 29, 34] [3, 9, 19, 29, 35, 40] [8, 10, 24, 35, 36, 38] [6, 9, 13, 18, 29, 41] [8, 12, 15, 18, 44, 45] [3, 5, 13, 23, 41, 44] [6, 13, 28, 29, 43, 45] [10, 14, 27, 33, 35, 44] [7, 13, 14, 17, 34, 39] [1, 7, 16, 17, 37, 43] [3, 7, 14, 21, 27, 44] [13, 28, 32, 33, 34, 36] [2, 21, 24, 27, 28, 34] [4, 7, 20, 27, 30, 35] [6, 9, 20, 33, 39, 40] [7, 17, 19, 25, 39, 45] [28, 29, 32, 33, 36, 43] [5, 7, 13, 23, 24, 38] [4, 9, 15, 28, 40, 42] [17, 20, 29, 35, 37, 39] [1, 4, 5, 19, 31, 34] [1, 3, 21, 25, 32, 36] [8, 9, 14, 16, 23, 27] [8, 10, 22, 24, 29, 31] [7, 10, 20, 28, 33, 42] [15, 16, 26, 27, 34, 35] -------------------------- |
반응형
'Python' 카테고리의 다른 글
(파이썬) 두 파일의 내용이 같은지 비교하기 (0) | 2023.06.24 |
---|---|
(파이썬) 2의 제곱승 구하기 (0) | 2023.06.23 |
(파이썬) ASCII Code 아스키 코드 출력 (0) | 2023.05.29 |
(파이썬) 가위바위보 게임 (0) | 2023.05.24 |
(파이썬) 정렬 sort()메서드와 sorted() 함수 (0) | 2023.04.29 |