Skip to content

Commit 7f9eae4

Browse files
committed
fix: PEP8 규격 수정
1 parent 44446ed commit 7f9eae4

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

src/lotto/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# src/lotto/__init__.py
22

33
# 📌 이 패키지는 로또 관련 기능을 제공하는 모듈입니다.
4-
# 외부에서 `from lotto import Lotto`와 같은 방식으로 사용할 수 있도록
4+
# 외부에서 `from lotto import Lotto`와 같은 방식으로 사용할 수 있도록
55
# 필요한 모듈을 여기에 등록하세요.
66
#
77
# ✅ 새로운 모듈을 추가할 경우:

src/lotto/lotto.py

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
class Rank(Enum):
66
"""
7-
로또 당첨 순위 정의하는 클래스
7+
로또 당첨 순위를 정의하는 클래스.
8+
9+
- FIFTH: 3개 일치 (5,000원)
10+
- FOURTH: 4개 일치 (50,000원)
11+
- THIRD: 5개 일치 (1,500,000원)
12+
- SECOND: 5개 + 보너스 번호 일치 (30,000,000원)
13+
- FIRST: 6개 일치 (2,000,000,000원)
14+
- NONE: 0개 일치 (당첨 없음)
815
"""
916
FIFTH = (3, False, 5_000)
1017
FOURTH = (4, False, 50_000)
@@ -15,7 +22,12 @@ class Rank(Enum):
1522

1623
def __init__(self, match_cnt, bonus_match, prize):
1724
"""
18-
Rank 객체 초기화
25+
Rank 객체 초기화.
26+
27+
Args:
28+
match_cnt (int): 일치하는 번호 개수
29+
bonus_match (bool): 보너스 번호 일치 여부
30+
prize (int): 당첨 금액
1931
"""
2032
self.match_cnt = match_cnt
2133
self.bonus_match = bonus_match
@@ -24,23 +36,50 @@ def __init__(self, match_cnt, bonus_match, prize):
2436
@classmethod
2537
def get_rank(cls, match_cnt, bonus):
2638
"""
27-
일치 개수와 보너스 번호 여부를 기반으로 당첨 순위 반환
39+
일치 개수와 보너스 번호 여부를 기반으로 당첨 순위 반환.
40+
41+
Args:
42+
match_cnt (int): 일치하는 번호 개수
43+
bonus (bool): 보너스 번호 일치 여부
44+
45+
Returns:
46+
Rank: 해당하는 당첨 순위
2847
"""
2948
for rank in cls:
3049
if rank.match_cnt == match_cnt and rank.bonus_match == bonus:
3150
return rank
3251
return cls.NONE
3352

3453

35-
class Lotto():
36-
"""로또 번호 및 당첨 결과를 처리하는 클래스"""
54+
class Lotto:
55+
"""
56+
로또 번호 및 당첨 결과를 처리하는 클래스.
57+
58+
- 1~45 사이의 서로 다른 6개의 숫자를 가짐.
59+
- 로또 번호 검증 및 생성 기능 포함.
60+
"""
3761
ERROR_MESSAGE = "[ERROR] 구입 금액이 잘못되었습니다."
62+
3863
def __init__(self, numbers: list[int]):
64+
"""
65+
Lotto 객체 초기화.
66+
67+
Args:
68+
numbers (list[int]): 1~45 사이의 6개 정수 리스트
69+
"""
3970
self._validate(numbers)
4071
self._numbers = sorted(numbers)
4172

4273
def _validate(self, numbers: list[int]):
43-
"""로또 번호 검증: 개수, 중복, 범위"""
74+
"""
75+
로또 번호 검증: 개수, 중복, 범위 확인.
76+
77+
Args:
78+
numbers (list[int]): 1~45 사이의 6개 정수 리스트
79+
80+
Raises:
81+
ValueError: 유효하지 않은 로또 번호일 경우 예외 발생
82+
"""
4483
if len(numbers) != 6:
4584
raise ValueError("로또 번호는 정확히 6개여야 합니다.")
4685
if len(set(numbers)) != 6:
@@ -50,14 +89,28 @@ def _validate(self, numbers: list[int]):
5089

5190
@classmethod
5291
def generate_randomlotto(cls):
53-
"""무작위 로또 번호 생성"""
54-
return cls(random.sample(range(1, 46), 6))
92+
"""
93+
무작위 로또 번호 생성.
5594
95+
Returns:
96+
Lotto: 생성된 로또 객체
97+
"""
98+
return cls(random.sample(range(1, 46), 6))
5699

57100
def get_numbers(self):
58-
return self._numbers
101+
"""
102+
로또 번호 반환.
59103
104+
Returns:
105+
list[int]: 정렬된 로또 번호 리스트
106+
"""
107+
return self._numbers
60108

61109
def __str__(self):
62-
"""str 형식으로 변환하여 반환"""
110+
"""
111+
문자열 변환.
112+
113+
Returns:
114+
str: 로또 번호 리스트를 문자열로 반환
115+
"""
63116
return str(self._numbers)

src/lotto/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ def print_results(results, total_prize, amount):
9494
for rank in Rank:
9595
if rank == Rank.SECOND:
9696
print(
97-
f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {results[rank]}개"
97+
f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - "
98+
f"{results[rank]}개"
9899
)
99100

100101
if rank != Rank.NONE and rank != Rank.SECOND:
101102
print(
102-
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - {results[rank]}개"
103+
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - "
104+
f"{results[rank]}개"
103105
)
104106

105107
print(f"총 수익률은 {profit_percentage}%입니다.")
@@ -108,7 +110,7 @@ def print_results(results, total_prize, amount):
108110
def main():
109111
"""로또 게임 실행"""
110112
amount = prompt_purchase_amount()
111-
tickets = [Lotto.generate_random_lotto() for _ in range(amount)]
113+
tickets = [Lotto.generate_randomlotto() for _ in range(amount)]
112114
print_lotto_tickets(tickets)
113115

114116
winning_numbers = prompt_winning_numbers()

0 commit comments

Comments
 (0)