-
Notifications
You must be signed in to change notification settings - Fork 5
[로또] 송채원 미션 제출합니다. #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
사용자에게 금액 입력 받아 유효성 검사한 뒤 로또 발행하여 출력
당첨 번호, 보너스 번호 입력 함수 추가 및 유효성 검사와 에러 문구 출력 기능 추가
main.py에서 이전
등수 계산하는 기능 추가
enum을 사용한 당첨 개수에 따른 수익률 계산 및 출력 기능
결과 출력 시 2등 출력 상세화
raise 추가
Walkthrough본 PR은 복권 시스템에 대한 문서 업데이트와 함께 여러 파일에 걸쳐 기능을 확장하는 변경 사항을 포함합니다.
Changes
Sequence Diagram(s)sequenceDiagram
participant U as 사용자
participant M as 메인 시스템
participant L as Lotto 객체
participant R as Rank 처리
U->>M: 구매 금액 입력 (input_price)
M->>L: 복권 번호 생성 (generate_num)
L-->>M: 생성된 복권 번호 반환
M->>U: 당첨 번호 입력 요청 (user_input)
U->>M: 당첨 번호 입력
M->>U: 보너스 번호 입력 요청 (bonus_input)
U->>M: 보너스 번호 입력
M->>L: 번호 비교 요청 (compare_lotto)
L->>R: 일치 여부 및 순위 계산 (get_rank)
R-->>L: 순위 결과 반환
L-->>M: 비교 결과 반환
M->>U: 최종 결과 출력 (print_result)
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (5)
src/lotto/lotto.py (1)
1-4
: 모듈 최상단에 주석 혹은 모듈 docstring을 추가해주세요.파이프라인에서 모듈에 대한 docstring이 누락되었다고 경고하고 있습니다. 모듈의 용도와 간단한 설명을 포함하는 docstring을 맨 위에 추가해주시면 좋겠습니다.
🧰 Tools
🪛 GitHub Actions: Check Function Length
[warning] 1-1: Missing module docstring (missing-module-docstring)
🪛 GitHub Actions: Check No External Libraries
[error] 1-1: External library detected: typing in src/lotto/lotto.py
src/lotto/__init__.py (1)
8-8
:Rank
임포트 사용 여부 재검토.해당 라인에서
from .lotto import Rank
를 선언했지만, 실제로 사용되지 않는다고 파이프라인이 경고합니다.
- 이 패키지를 외부에서 사용할 때
Rank
도 공개 API로 제공하려는 의도라면,__all__
에 추가하거나 문서화하는 방안을 권장합니다.- 그렇지 않다면 사용되지 않는 임포트이므로 제거하는 편이 좋습니다.
또한, 파일의 마지막에 줄바꿈이 누락되었다고 하니 추가해주세요.🧰 Tools
🪛 Ruff (0.8.2)
8-8:
.lotto.Rank
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
🪛 GitHub Actions: Check PEP8 Style
[warning] 8-8: '.lotto.Rank' imported but unused
[warning] 8-8: no newline at end of file
🪛 GitHub Actions: Check Function Length
[warning] 8-8: Final newline missing (missing-final-newline)
🪛 GitHub Actions: Check Indentation Depth
[warning] 8-8: Final newline missing (missing-final-newline)
src/lotto/main.py (3)
24-36
:while True:
루프 내에서 예외 발생 시 바로raise
하면 반복되지 않습니다.
input_price
함수는while True:
로 감싸고 있지만, 예외가 발생하면 재시도 없이 함수를 종료시키고 있습니다. 사용자가 올바른 금액을 입력할 때까지 반복하도록 의도했다면,raise
대신 오류 메시지를 출력한 뒤continue
를 사용하여 루프를 계속 도는 방식으로 수정할 필요가 있습니다.
130-130
: 너무 긴 문자열은 줄바꿈으로 가독성을 높이세요.파이프라인에서 79자를 초과하는 라인 길이에 대한 경고가 있습니다. 문자열 포매팅 시 줄바꿈을 추가하면 가독성이 개선됩니다.
- f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {result[rank]}개" + f"{rank.match_cnt}개 일치, 보너스 볼 일치 " + f"({rank.prize:,}원) - {result[rank]}개"🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 130-130: line too long (85 > 79 characters)
133-133
: 조건문 간소화를 고려하세요.
if rank != Rank.NONE and rank != Rank.SECOND:
조건문은if rank not in (Rank.NONE, Rank.SECOND):
형태로 간결하게 표현할 수 있습니다.🧰 Tools
🪛 GitHub Actions: Check Function Length
[warning] 133-133: Consider merging these comparisons with 'in' by using 'rank not in (Rank.NONE, Rank.SECOND)'. Use a set instead if elements are hashable. (consider-using-in)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
docs/README.md
(1 hunks)src/lotto/__init__.py
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/lotto/__init__.py
8-8: .lotto.Rank
imported but unused; consider removing, adding to __all__
, or using a redundant alias
(F401)
src/lotto/main.py
1-1: random
imported but unused
Remove unused import: random
(F401)
🪛 GitHub Actions: Check PEP8 Style
src/lotto/__init__.py
[warning] 6-6: '.lotto.Lotto' imported but unused
[warning] 8-8: '.lotto.Rank' imported but unused
[warning] 8-8: no newline at end of file
src/lotto/main.py
[warning] 1-1: 'random' imported but unused
[error] 130-130: line too long (85 > 79 characters)
🪛 GitHub Actions: Check Function Length
src/lotto/__init__.py
[warning] 8-8: Final newline missing (missing-final-newline)
[warning] 1-1: Missing module docstring (missing-module-docstring)
src/lotto/lotto.py
[warning] 1-1: Missing module docstring (missing-module-docstring)
src/lotto/main.py
[warning] 1-1: Missing module docstring (missing-module-docstring)
[warning] 133-133: Consider merging these comparisons with 'in' by using 'rank not in (Rank.NONE, Rank.SECOND)'. Use a set instead if elements are hashable. (consider-using-in)
[warning] 1-1: Unused import random (unused-import)
🪛 GitHub Actions: Check Indentation Depth
src/lotto/__init__.py
[warning] 8-8: Final newline missing (missing-final-newline)
🪛 GitHub Actions: Check No External Libraries
src/lotto/lotto.py
[error] 1-1: External library detected: typing in src/lotto/lotto.py
🔇 Additional comments (4)
src/lotto/lotto.py (2)
2-2
: ‘typing’ 라이브러리에 대한 파이프라인 경고 확인 필요.
typing
은 Python 3 표준 라이브러리로 분류되지만, 파이프라인에서 외부 라이브러리로 잘못 인식할 수 있으니 설정을 재검토하시기 바랍니다. 환경 상 문제로 인해 허용되지 않는다면, 타입 힌트를 제외하거나 별도 방식으로 처리해야 할 수도 있습니다.
30-79
: 전체 로직 전반적으로 견고하고 가독성이 좋습니다.로또 번호 생성(
generate_num
), 게터(get_numbers
), 문자열 표현(__str__
), 그리고Rank
열거형과get_rank
메서드까지 구조가 깔끔하고 명확합니다. 별다른 문법 오류나 로직적 문제가 없으며, 메서드 간 결합도가 적절해 유지 보수 측면에서도 좋습니다.docs/README.md (2)
1-9
: 컴퓨터 기능 구현이 완료되었습니다!모든 필수 기능이 체크리스트에 명확하게 정리되어 있으며, 구현이 완료된 것으로 표시되어 있습니다.
10-13
: 사용자 기능 구현이 완료되었습니다!사용자 입력과 관련된 모든 기능이 구현되어 있습니다.
if len(numbers) != 6: | ||
raise ValueError | ||
raise ValueError("로또 번호는 6개여야 합니다.") | ||
if len(set(numbers)) < 6: | ||
raise ValueError("로또 번호는 중복되어서는 안됩니다.") | ||
if max(numbers) > 46 or min(numbers) < 1: | ||
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
숫자 범위 검증 조건에 오프바이원(off-by-one) 오류가 있습니다.
1~45
범위를 검증하려면 max(numbers) > 45
를 확인하여 46 이상의 값이 나오면 예외를 발생시켜야 합니다. 현재 코드는 > 46
로 설정되어 46이 통과할 여지가 있습니다.
다음과 같이 수정해보세요:
- if max(numbers) > 46 or min(numbers) < 1:
+ if max(numbers) > 45 or min(numbers) < 1:
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if len(numbers) != 6: | |
raise ValueError | |
raise ValueError("로또 번호는 6개여야 합니다.") | |
if len(set(numbers)) < 6: | |
raise ValueError("로또 번호는 중복되어서는 안됩니다.") | |
if max(numbers) > 46 or min(numbers) < 1: | |
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.") | |
if len(numbers) != 6: | |
raise ValueError("로또 번호는 6개여야 합니다.") | |
if len(set(numbers)) < 6: | |
raise ValueError("로또 번호는 중복되어서는 안됩니다.") | |
if max(numbers) > 45 or min(numbers) < 1: | |
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.") |
src/lotto/main.py
Outdated
import random | ||
from lotto import Lotto, Rank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
사용되지 않는 random
임포트를 제거해주세요.
파이프라인에서 random
모듈이 사용되지 않는다고 경고하고 있습니다. 이 파일 내에서 random
을 사용하지 않으므로 해당 임포트를 삭제하시는 편이 좋습니다.
- import random
from lotto import Lotto, Rank
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import random | |
from lotto import Lotto, Rank | |
from lotto import Lotto, Rank |
🧰 Tools
🪛 Ruff (0.8.2)
1-1: random
imported but unused
Remove unused import: random
(F401)
🪛 GitHub Actions: Check PEP8 Style
[warning] 1-1: 'random' imported but unused
🪛 GitHub Actions: Check Function Length
[warning] 1-1: Missing module docstring (missing-module-docstring)
[warning] 1-1: Unused import random (unused-import)
src/lotto/main.py
Outdated
if int(bonus_num) > 46 or int(bonus_num) < 1: | ||
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보너스 번호도 1~45 범위를 준수하도록 조건을 수정해주세요.
if int(bonus_num) > 46:
구문으로 인해 46이 허용될 여지가 있습니다. 로또 번호 범위가 1~45라면, >= 46
일 때 오류를 발생시키는 것이 맞습니다.
- if int(bonus_num) > 46 or int(bonus_num) < 1:
+ if int(bonus_num) > 45 or int(bonus_num) < 1:
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if int(bonus_num) > 46 or int(bonus_num) < 1: | |
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.") | |
if int(bonus_num) > 45 or int(bonus_num) < 1: | |
raise ValueError("로또 번호의 숫자 범위는 1~45까지입니다.") |
docs/README.md
Outdated
#### 조건 | ||
* [ ] 함수나 메서드 길이 15라인 초과 금지 | ||
* [ ] else 예약어 사용 금지 | ||
* [ ] Enum 적용 | ||
* [ ] 로직 분리 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
조건 항목들의 구현 상태를 확인해주세요.
조건 섹션의 모든 항목이 미완료로 표시되어 있습니다. 코드베이스에서 이러한 조건들의 실제 구현 상태를 확인하겠습니다.
🏁 Script executed:
#!/bin/bash
# 코드베이스에서 조건들의 구현 상태를 확인합니다
echo "1. 함수/메서드 길이 확인 (15라인 초과 여부)"
rg -U "def.*?}|def.*?\n\n" -A 20
echo "2. else 키워드 사용 확인"
rg "\belse\b"
echo "3. Enum 사용 확인"
rg "class.*?\(.*?Enum.*?\):"
echo "4. 로직 분리 확인 (파일 구조)"
find . -type f -name "*.py" | grep "src/lotto"
Length of output: 497
검증 결과: 구현 조건은 모두 충족됨 (문서 업데이트 필요)
검증 스크립트 결과를 종합해보면:
-
함수/메서드 길이 (15라인 초과 금지):
별도의 초과 사례가 검출되지 않아, 해당 제한은 잘 지켜지고 있는 것으로 보입니다. -
else 예약어 사용 금지:
실제 코드에서는 else 예약어 사용 위반 사례가 발견되지 않았습니다. (문서 상에만 관련 문구가 남아 있음) -
Enum 적용:
src/lotto/lotto.py
에서class Rank(Enum):
를 확인할 수 있어 Enum 적용이 이루어졌습니다. -
로직 분리:
src/lotto/main.py
,src/lotto/lotto.py
,src/lotto/__init__.py
파일이 존재하는 것으로 보아 로직 분리가 잘 구현되어 있습니다.
다만, docs/README.md (15~19라인)에 남아 있는 체크리스트 항목들이 실제 구현 상태와 일치하지 않으므로, 문서상의 체크리스트 상태를 업데이트하여 실제 구현과 맞추는 것을 권장합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/lotto/lotto.py (1)
49-78
: 상수 값에 대한 설명을 추가하면 좋겠습니다.각 순위별 상수 값(당첨금, 일치 개수 등)에 대한 설명을 문서화하면 코드의 가독성이 향상될 것 같습니다.
예시:
class Rank(Enum): """ 로또 당첨 순위 정의하는 클래스 + + 각 순위별 정보: + - match_cnt: 일치하는 번호의 개수 + - bonus_match: 보너스 번호 일치 여부 + - prize: 당첨금액 """src/lotto/main.py (1)
132-138
: 코드 포맷팅과 가독성을 개선해주세요.
- 줄 길이가 PEP8 기준(79자)을 초과합니다.
- 닫는 괄호의 들여쓰기가 일관되지 않습니다.
다음과 같이 수정하는 것을 제안드립니다:
- f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {result[rank]}개" + f"{rank.match_cnt}개 일치, 보너스 볼 일치" + f" ({rank.prize:,}원) - {result[rank]}개" ) if rank != Rank.NONE and rank != Rank.SECOND: - print(f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " - f"{result[rank]}개" + print( + f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - {result[rank]}개" )🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[warning] 132-132: line too long (85 > 79 characters)
[warning] 138-138: closing bracket does not match visual indentation
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/lotto/__init__.py
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/lotto/init.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/lotto/main.py
[warning] 47-47: src/lotto/main.py#L47
Added line #L47 was not covered by tests
[warning] 49-49: src/lotto/main.py#L49
Added line #L49 was not covered by tests
[warning] 72-73: src/lotto/main.py#L72-L73
Added lines #L72 - L73 were not covered by tests
[warning] 84-85: src/lotto/main.py#L84-L85
Added lines #L84 - L85 were not covered by tests
[warning] 93-93: src/lotto/main.py#L93
Added line #L93 was not covered by tests
[warning] 95-95: src/lotto/main.py#L95
Added line #L95 was not covered by tests
[warning] 97-97: src/lotto/main.py#L97
Added line #L97 was not covered by tests
src/lotto/lotto.py
[warning] 27-27: src/lotto/lotto.py#L27
Added line #L27 was not covered by tests
🪛 GitHub Actions: Check PEP8 Style
src/lotto/main.py
[warning] 7-7: expected 2 blank lines, found 1
[warning] 132-132: line too long (85 > 79 characters)
[warning] 138-138: closing bracket does not match visual indentation
🪛 GitHub Actions: Check No External Libraries
src/lotto/lotto.py
[error] 1-1: External library detected: enum in src/lotto/lotto.py
🔇 Additional comments (5)
src/lotto/lotto.py (3)
1-8
: LGTM! 문서화가 잘 되어있습니다.클래스의 목적과 책임이 명확하게 문서화되어 있습니다.
🧰 Tools
🪛 GitHub Actions: Check No External Libraries
[error] 1-1: External library detected: enum in src/lotto/lotto.py
22-27
: 숫자 범위 검증 로직을 수정해주세요.이전 리뷰에서 지적된 오프바이원(off-by-one) 오류가 아직 수정되지 않았습니다.
또한, 이 검증 로직에 대한 테스트 케이스가 누락되어 있습니다.
테스트 케이스를 추가하시겠습니까? 다음과 같은 테스트 케이스를 제안드립니다:
- 유효한 범위(1~45)의 숫자
- 범위를 벗어난 숫자(0, 46)
- 중복된 숫자
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 27-27: src/lotto/lotto.py#L27
Added line #L27 was not covered by tests
29-34
: LGTM! 랜덤 번호 생성이 적절하게 구현되었습니다.
random.sample
을 사용하여 중복 없는 난수 생성을 보장하고 있습니다.src/lotto/main.py (2)
96-97
: 보너스 번호 범위 검증 로직을 수정해주세요.이전 리뷰에서 지적된 오프바이원(off-by-one) 오류가 아직 수정되지 않았습니다.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 97-97: src/lotto/main.py#L97
Added line #L97 was not covered by tests
72-97
: 테스트 커버리지를 개선해주세요.다음 에러 케이스들에 대한 테스트가 누락되어 있습니다:
- 당첨 번호 입력 오류
- 보너스 번호 입력 오류
- 보너스 번호 유효성 검사 실패
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 72-73: src/lotto/main.py#L72-L73
Added lines #L72 - L73 were not covered by tests
[warning] 84-85: src/lotto/main.py#L84-L85
Added lines #L84 - L85 were not covered by tests
[warning] 93-93: src/lotto/main.py#L93
Added line #L93 was not covered by tests
[warning] 95-95: src/lotto/main.py#L95
Added line #L95 was not covered by tests
[warning] 97-97: src/lotto/main.py#L97
Added line #L97 was not covered by tests
while True: | ||
try: | ||
print("구입금액을 입력해 주세요.") | ||
price = input() | ||
return validate_price(price) | ||
except ValueError as e: | ||
print(f"[ERROR] {e}") | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 처리 로직을 개선해주세요.
에러를 출력하고 다시 발생시키는 것은 중복된 처리입니다. 다음과 같이 수정하는 것이 좋겠습니다:
try:
print("구입금액을 입력해 주세요.")
price = input()
return validate_price(price)
except ValueError as e:
print(f"[ERROR] {e}")
- raise
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
while True: | |
try: | |
print("구입금액을 입력해 주세요.") | |
price = input() | |
return validate_price(price) | |
except ValueError as e: | |
print(f"[ERROR] {e}") | |
raise | |
while True: | |
try: | |
print("구입금액을 입력해 주세요.") | |
price = input() | |
return validate_price(price) | |
except ValueError as e: | |
print(f"[ERROR] {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
src/lotto/main.py (1)
31-38
: 🛠️ Refactor suggestion에러 처리 로직을 개선해주세요.
현재 코드는 에러를 출력하고 다시 발생시키고 있습니다. 이는 중복된 처리입니다. while 루프 안에서 에러를 출력하고 계속 진행하는 것이 더 적절합니다.
try: print("구입금액을 입력해 주세요.") price = input() return validate_price(price) except ValueError as e: print(f"[ERROR] {e}") - raise
🧹 Nitpick comments (3)
src/lotto/__init__.py (2)
2-2
: 후행 공백을 제거해주세요.코드의 가독성을 위해 줄 끝의 불필요한 공백을 제거하는 것이 좋습니다.
-# 외부에서 `from lotto import Lotto`와 같은 방식으로 사용할 수 있도록 +# 외부에서 `from lotto import Lotto`와 같은 방식으로 사용할 수 있도록🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 2-2: Trailing whitespace (trailing-whitespace)
🪛 GitHub Actions: Check PEP8 Style
[warning] 2-2: trailing whitespace
14-15
:__all__
정의를 한 줄로 작성하는 것이 좋습니다.현재
__all__
을 두 줄로 나누어 정의하고 있습니다. 가독성과 유지보수를 위해 한 줄로 작성하는 것이 좋습니다.-__all__ = ["Lotto"] -__all__.append("Rank") +__all__ = ["Lotto", "Rank"]src/lotto/main.py (1)
132-134
: 들여쓰기를 일관성 있게 수정해주세요.문자열 연결 부분의 들여쓰기가 일관성이 없습니다. PEP 8 스타일 가이드를 따라 수정하는 것이 좋습니다.
- print(f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " - f"{result[rank]}개" - ) + print(f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " + f"{result[rank]}개") - print(f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " - f"{result[rank]}개" - ) + print(f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " + f"{result[rank]}개")Also applies to: 137-139
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 134-134: closing bracket does not match visual indentation
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
docs/README.md
(1 hunks)src/lotto/__init__.py
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/README.md
🧰 Additional context used
🪛 GitHub Actions: Check PEP8 Style
src/lotto/main.py
[error] 134-134: closing bracket does not match visual indentation
[error] 139-139: closing bracket does not match visual indentation
src/lotto/__init__.py
[warning] 2-2: trailing whitespace
[error] 11-11: '.lotto.Rank' imported but unused
🪛 Ruff (0.8.2)
src/lotto/__init__.py
11-11: .lotto.Rank
imported but unused; consider removing, adding to __all__
, or using a redundant alias
(F401)
🪛 GitHub Actions: Check No External Libraries
src/lotto/__init__.py
[error] 1-1: External library detected: lotto in src/lotto/init.py
🪛 GitHub Actions: Check Indentation Depth
src/lotto/__init__.py
[warning] 2-2: Trailing whitespace (trailing-whitespace)
🔇 Additional comments (2)
src/lotto/lotto.py (2)
5-46
: 잘 구현된 Lotto 클래스입니다!
- 명확한 docstring
- 적절한 유효성 검사
- 효율적인 랜덤 번호 생성
- 깔끔한 인터페이스 제공
49-78
: Rank 클래스가 잘 설계되었습니다!
- Enum을 활용한 깔끔한 구현
- 당첨금과 매칭 조건이 명확하게 정의됨
- 보너스 번호 처리가 잘 구현됨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/lotto/__init__.py (1)
14-15
:__all__
정의를 더 간결하게 수정해주세요.현재
__all__
리스트에append
를 사용하여Rank
를 추가하고 있습니다. 초기 정의에서 한 번에 모든 항목을 포함하는 것이 더 명확합니다.다음과 같이 수정하는 것을 추천드립니다:
-__all__ = ["Lotto"] -__all__.append("Rank") +__all__ = ["Lotto", "Rank"]src/lotto/main.py (3)
45-51
: 에러 메시지에서 중복된 [ERROR] 접두사를 제거해주세요.
validate_price
함수의 에러 메시지에[ERROR]
접두사가 포함되어 있지만, 이미 출력 시점에서 추가되고 있습니다.다음과 같이 수정하는 것을 추천드립니다:
if not price.isdigit(): - raise ValueError("[ERROR] 숫자를 입력해 주세요.\n") + raise ValueError("숫자를 입력해 주세요.\n")
126-126
: 수익률 계산 로직을 별도의 함수로 분리하는 것이 좋겠습니다.수익률 계산 로직이
print_result
함수 내에 직접 구현되어 있습니다. 이 로직을 별도의 함수로 분리하면 재사용성과 테스트 용이성이 향상될 것 같습니다.다음과 같은 분리를 제안드립니다:
def calculate_profit_rate(total_prize, count): """ 총 수익률을 계산하여 반환 """ return round((total_prize / (count * 1000)) * 100, 2) def print_result(result, total_prize, count): profit_rate = calculate_profit_rate(total_prize, count) # ... 나머지 출력 로직 ...
130-138
: 당첨 결과 출력 로직을 개선해주세요.현재 코드는 2등과 그 외 등수를 구분하여 출력하고 있어 복잡합니다. 또한
Rank.NONE
을 명시적으로 제외하는 조건이 있습니다.다음과 같이 단순화하는 것을 추천드립니다:
def print_result(result, total_prize, count): print("\n당첨 통계") print("---") for rank in Rank: if rank == Rank.NONE: continue match_text = f"{rank.match_cnt}개 일치" if rank == Rank.SECOND: match_text += ", 보너스 볼 일치" print(f"{match_text} ({rank.prize:,}원) - {result[rank]}개")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lotto/__init__.py
(2 hunks)src/lotto/main.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/lotto/__init__.py
11-11: .lotto.Rank
imported but unused; consider removing, adding to __all__
, or using a redundant alias
(F401)
🪛 GitHub Actions: Check Indentation Depth
src/lotto/__init__.py
[warning] 19-19: Final newline missing (missing-final-newline)
🪛 GitHub Actions: Check No External Libraries
src/lotto/__init__.py
[error] 1-1: External library detected: lotto in src/lotto/init.py
🪛 GitHub Actions: Check PEP8 Style
src/lotto/__init__.py
[warning] 11-11: '.lotto.Rank' imported but unused
[warning] 19-19: no newline at end of file
🔇 Additional comments (1)
src/lotto/main.py (1)
31-38
: 에러 처리 로직을 개선해주세요.에러를 출력하고 다시 발생시키는 것은 중복된 처리입니다. 이전 리뷰에서도 지적된 사항입니다.
다음과 같이 수정하는 것이 좋겠습니다:
try: print("구입금액을 입력해 주세요.") price = input() return validate_price(price) except ValueError as e: print(f"[ERROR] {e}") - raise
src/lotto/__init__.py
Outdated
# 💡 예시: 새로운 모듈을 추가할 때 | ||
# from .other_module import OtherClass # 🆕 예: 새로운 클래스 추가 시 | ||
# __all__.append("OtherClass") # `__all__`에 추가하여 외부에서 접근 가능하게 함. | ||
# __all__.append("OtherClass") # `__all__`에 추가하여 외부에서 접근 가능하게 함. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
파일 끝에 개행을 추가해주세요.
파이프라인 검사에서 파일 끝에 개행이 없다고 경고하고 있습니다.
파일 끝에 빈 줄을 추가해주세요:
# __all__.append("OtherClass") # `__all__`에 추가하여 외부에서 접근 가능하게 함.
+
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# __all__.append("OtherClass") # `__all__`에 추가하여 외부에서 접근 가능하게 함. | |
# __all__.append("OtherClass") # `__all__`에 추가하여 외부에서 접근 가능하게 함. | |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 19-19: Final newline missing (missing-final-newline)
🪛 GitHub Actions: Check PEP8 Style
[warning] 19-19: no newline at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/lotto/__init__.py (1)
14-15
: all 리스트를 더 명확하게 정의하는 것이 좋겠습니다.
append()
대신 리스트에 직접 추가하는 것이 코드의 가독성과 유지보수성을 높일 수 있습니다.다음과 같이 수정하는 것을 제안합니다:
-__all__ = ["Lotto"] -__all__.append("Rank") +__all__ = ["Lotto", "Rank"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lotto/__init__.py
(2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/lotto/__init__.py
11-11: .lotto.Rank
imported but unused; consider removing, adding to __all__
, or using a redundant alias
(F401)
🪛 GitHub Actions: Check PEP8 Style
src/lotto/__init__.py
[warning] 11-11: '.lotto.Rank' imported but unused
🔇 Additional comments (2)
src/lotto/__init__.py (2)
10-11
: LGTM! Rank 클래스 가져오기가 적절히 추가되었습니다.
Rank
클래스를 가져오고__all__
에 추가하여 외부에서 사용할 수 있도록 한 것이 좋습니다.🧰 Tools
🪛 Ruff (0.8.2)
11-11:
.lotto.Rank
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
🪛 GitHub Actions: Check PEP8 Style
[warning] 11-11: '.lotto.Rank' imported but unused
20-20
: 파일 끝에 개행을 추가해주세요.파이프라인 검사에서 파일 끝에 개행이 없다고 경고하고 있습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/lotto/main.py (2)
71-74
: 에러 메시지를 더 구체적으로 개선하면 좋겠습니다.사용자가 잘못된 입력을 했을 때 어떤 형식으로 입력해야 하는지 안내하면 좋겠습니다.
try: user_num = list(map(int, input().split(","))) return Lotto(user_num).get_numbers() except ValueError as e: - print(f"[ERROR] {e}") + print(f"[ERROR] {e}\n올바른 입력 형식: 1,2,3,4,5,6")
122-140
: 출력 형식을 상수로 분리하면 좋겠습니다.출력 문자열 템플릿을 상수로 분리하면 유지보수성이 향상될 것 같습니다.
+RESULT_FORMAT = { + 'SECOND': "{}개 일치, 보너스 볼 일치 ({:,}원) - {}개", + 'NORMAL': "{}개 일치 ({:,}원) - {}개", + 'PROFIT': "총 수익률은 {}%입니다." +} def print_result(result, total_prize, count): """ 당첨 결과 출력 """ profit_rate = round((total_prize / (count * 1000)) * 100, 2) print("\n당첨 통계") print("---") for rank in Rank: if rank == Rank.SECOND: - print(f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " - f"{result[rank]}개") + print(RESULT_FORMAT['SECOND'].format( + rank.match_cnt, rank.prize, result[rank])) if rank != Rank.NONE and rank != Rank.SECOND: - print(f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " - f"{result[rank]}개") + print(RESULT_FORMAT['NORMAL'].format( + rank.match_cnt, rank.prize, result[rank])) - print(f"총 수익률은 {profit_rate}%입니다.") + print(RESULT_FORMAT['PROFIT'].format(profit_rate))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lotto/__init__.py
(1 hunks)src/lotto/main.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/lotto/init.py
🧰 Additional context used
🪛 GitHub Actions: Check PEP8 Style
src/lotto/main.py
[error] 1-1: E231 missing whitespace after ','
🔇 Additional comments (5)
src/lotto/main.py (5)
8-25
: 구현이 잘 되었습니다!메인 함수가 명확한 문서화와 함께 로또 프로그램의 핵심 기능을 잘 구현하고 있습니다.
31-38
: 에러 처리 로직을 개선해주세요.에러를 출력하고 다시 발생시키는 것은 중복된 처리입니다. 다음과 같이 수정하는 것이 좋겠습니다:
try: print("구입금액을 입력해 주세요.") price = input() return validate_price(price) except ValueError as e: print(f"[ERROR] {e}") - raise
41-53
: 검증 로직이 잘 구현되었습니다!가격 입력에 대한 다양한 유효성 검사와 명확한 에러 메시지를 잘 구현하였습니다.
89-101
: 보너스 번호 검증이 잘 구현되었습니다!보너스 번호에 대한 모든 필요한 검증(숫자 여부, 중복 확인, 범위 검사)이 잘 구현되어 있습니다.
103-120
: 로또 비교 로직이 효율적으로 구현되었습니다!set 연산을 활용한 번호 비교와 딕셔너리 컴프리헨션을 사용한 결과 저장이 매우 효율적입니다.
src/lotto/main.py
Outdated
@@ -1,6 +1,143 @@ | |||
from .lotto import Rank,Lotto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
PEP8 스타일 가이드를 준수해주세요.
쉼표 뒤에 공백이 누락되었습니다.
- from .lotto import Rank,Lotto
+ from .lotto import Rank, Lotto
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
from .lotto import Rank,Lotto | |
from .lotto import Rank, Lotto |
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 1-1: E231 missing whitespace after ','
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/lotto/main.py (4)
1-2
: 같은 모듈에서 가져오는 임포트를 하나로 통합해주세요.코드의 간결성을 위해 같은 모듈에서 가져오는 임포트는 하나의 라인으로 통합하는 것이 좋습니다.
-from lotto import Rank -from lotto import Lotto +from lotto import Rank, Lotto
42-54
: 가격 검증 로직에 대한 테스트 케이스를 추가해주세요.
validate_price
함수의 여러 검증 조건들이 테스트되지 않았습니다. 다음과 같은 케이스들에 대한 테스트가 필요합니다:
- 숫자가 아닌 입력
- 1000으로 나누어 떨어지지 않는 금액
- 1000원 미만의 금액
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 49-49: src/lotto/main.py#L49
Added line #L49 was not covered by tests
[warning] 51-51: src/lotto/main.py#L51
Added line #L51 was not covered by tests
65-76
: 사용자 입력 오류 처리에 대한 테스트를 추가해주세요.잘못된 형식의 입력이나 예외 상황에 대한 테스트 케이스가 누락되어 있습니다. 다음과 같은 케이스들에 대한 테스트가 필요합니다:
- 쉼표로 구분되지 않은 입력
- 숫자가 아닌 입력
- 잘못된 범위의 숫자 입력
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 74-75: src/lotto/main.py#L74-L75
Added lines #L74 - L75 were not covered by tests
78-102
: 보너스 번호 검증 로직에 대한 테스트를 추가해주세요.
validate_bonus
함수의 여러 검증 조건들이 테스트되지 않았습니다. 다음과 같은 케이스들에 대한 테스트가 필요합니다:
- 숫자가 아닌 입력
- 당첨 번호와 중복되는 경우
- 범위를 벗어난 숫자 입력
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 86-87: src/lotto/main.py#L86-L87
Added lines #L86 - L87 were not covered by tests
[warning] 95-95: src/lotto/main.py#L95
Added line #L95 was not covered by tests
[warning] 97-97: src/lotto/main.py#L97
Added line #L97 was not covered by tests
[warning] 99-99: src/lotto/main.py#L99
Added line #L99 was not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lotto/__init__.py
(2 hunks)src/lotto/main.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/lotto/init.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/lotto/main.py
[warning] 49-49: src/lotto/main.py#L49
Added line #L49 was not covered by tests
[warning] 51-51: src/lotto/main.py#L51
Added line #L51 was not covered by tests
[warning] 74-75: src/lotto/main.py#L74-L75
Added lines #L74 - L75 were not covered by tests
[warning] 86-87: src/lotto/main.py#L86-L87
Added lines #L86 - L87 were not covered by tests
[warning] 95-95: src/lotto/main.py#L95
Added line #L95 was not covered by tests
[warning] 97-97: src/lotto/main.py#L97
Added line #L97 was not covered by tests
[warning] 99-99: src/lotto/main.py#L99
Added line #L99 was not covered by tests
🔇 Additional comments (5)
src/lotto/main.py (5)
9-26
: 잘 구현되었습니다!메인 함수가 명확한 책임을 가지고 있으며, 각 단계가 잘 분리되어 있습니다.
32-39
: 에러 처리 로직을 개선해주세요.예외를 출력하고 다시 발생시키는 것은 중복된 처리입니다. 예외를 출력만 하고 루프를 계속 진행하도록 수정하는 것이 좋겠습니다.
try: print("구입금액을 입력해 주세요.") price = input() return validate_price(price) except ValueError as e: print(f"[ERROR] {e}") - raise
56-63
: 깔끔하게 구현되었습니다!출력 함수가 단일 책임을 잘 수행하고 있습니다.
104-121
: 효율적으로 구현되었습니다!집합 연산을 활용한 번호 비교와 결과 계산이 효율적으로 구현되어 있습니다.
123-141
: 결과 출력이 잘 구현되었습니다!수익률 계산과 결과 출력 형식이 명확하게 구현되어 있습니다.
Summary by CodeRabbit
새로운 기능
Rank
클래스와 관련된 기능이 추가되었습니다.문서