-
Notifications
You must be signed in to change notification settings - Fork 10
[숫자야구게임]소현우 제출합니다. #7
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?
The head ref may contain hidden characters: "\uC218\uC8152"
Conversation
Walkthrough
Changes
Sequence Diagram(s)sequenceDiagram
participant U as 사용자
participant M as main()
participant R as randnumber()
U->>M: 게임 실행, 숫자 입력 시도
M->>R: 비밀 숫자 생성 요청
R-->>M: 세 개의 랜덤 숫자 응답
loop 사용자 입력 반복
U->>M: 세 자리 숫자 입력
alt 입력값 유효하지 않음
M-->>U: ValueError 메시지 출력
else 입력값 유효함
M->>M: 입력값과 비밀 숫자 비교 (스트라이크/볼 계산)
M-->>U: 결과 메시지(스트라이크/볼) 출력
alt 정답 (3스트라이크)
M-->>U: 성공 메시지 출력 후 게임 종료
end
end
end
U->>M: 메뉴 입력 (종료 여부 결정)
Poem
Tip 🌐 Web search-backed reviews and chat
✨ 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 (
|
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: 3
🧹 Nitpick comments (2)
src/baseball/main.py (2)
2-2: 모듈 임포트 위치 조정Python에서는 모듈을 파일의 최상단에 임포트하는 것이 일반적입니다. 함수 내부에서 임포트하면 가독성이 떨어지고 예기치 않은 동작이 발생할 수 있습니다.
다음과 같이 수정하시길 권장합니다:
- import random +import random def main():
20-21: 변수 이름의 일관성 유지
strike_Cnt및ball_Cnt변수는 PEP8 스타일 가이드에 따라 소문자와 밑줄을 사용하여strike_cnt,ball_cnt로 명명하는 것이 좋습니다.다음과 같이 수정할 수 있습니다:
-strike_Cnt = 0 -ball_Cnt = 0 +strike_cnt = 0 +ball_cnt = 0그리고 코드 전체에서 해당 변수명 사용 부분을 동일하게 변경하시기 바랍니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/baseball/main.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/baseball/main.py
15-15: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
| raise ValueError(("잘못된 입력입니다")) | ||
|
|
||
|
|
||
| num_arr = [(num // 100), ((num // 10) % 10), (num % 10)] |
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
입력 숫자의 중복 검사 추가
숫자야구 게임에서는 서로 다른 세 자리 숫자를 사용합니다. 현재 입력된 숫자에서 중복된 자릿수에 대한 검사가 없으므로, 중복 여부를 확인하는 로직을 추가하는 것이 필요합니다.
다음과 같이 중복 검사를 추가해보세요:
num_arr = [(num // 100), ((num // 10) % 10), (num % 10)]
+if len(set(num_arr)) != 3:
+ print("각 자릿수는 서로 다른 숫자여야 합니다. 다시 입력해 주세요.")
+ continue📝 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.
| num_arr = [(num // 100), ((num // 10) % 10), (num % 10)] | |
| num_arr = [(num // 100), ((num // 10) % 10), (num % 10)] | |
| if len(set(num_arr)) != 3: | |
| print("각 자릿수는 서로 다른 숫자여야 합니다. 다시 입력해 주세요.") | |
| continue |
| if strike_Cnt == 3: | ||
| print("3스트라이크") | ||
| print("게임 종료") | ||
| break # 정답을 맞추면 게임 종료 | ||
| elif strike_Cnt == 0 and ball_Cnt == 0: | ||
| print("낫싱") | ||
| elif strike_Cnt == 1 and ball_Cnt == 1: | ||
| print("1볼 1스트라이크") | ||
| elif ball_Cnt == 3: | ||
| print("3볼") | ||
| else: | ||
| continue # 지정된 출력 패턴이 아닌 경우 무시하고 다시 입력받음 |
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.
게임 결과 출력 로직 개선
현재 코드는 특정한 스트라이크와 볼의 조합에 대해서만 결과를 출력하고 있습니다. 모든 경우에 대해 적절한 결과를 사용자에게 제공하기 위해 조건문을 일반화하는 것이 좋습니다.
다음과 같이 수정하여 모든 경우에 대응할 수 있습니다:
if strike_cnt == 3:
print("3스트라이크")
print("게임 종료")
break # 정답을 맞추면 게임 종료
elif strike_cnt == 0 and ball_cnt == 0:
print("낫싱")
else:
- if strike_Cnt == 1 and ball_Cnt == 1:
- print("1볼 1스트라이크")
- elif ball_Cnt == 3:
- print("3볼")
- else:
- continue # 지정된 출력 패턴이 아닌 경우 무시하고 다시 입력받음
+ result = ""
+ if ball_cnt > 0:
+ result += f"{ball_cnt}볼 "
+ if strike_cnt > 0:
+ result += f"{strike_cnt}스트라이크"
+ print(result.strip())Committable suggestion skipped: line range outside the PR's diff.
| if num < 100 or num > 999: # 3자리 숫자가 아닐 경우 | ||
| raise ValueError("3자리 숫자를 입력해야 합니다.") | ||
| except ValueError: | ||
| raise ValueError(("잘못된 입력입니다")) |
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.
예외 처리 로직 개선
except 블록 내에서 동일한 예외를 다시 발생시키면 프로그램이 종료될 수 있습니다. 사용자에게 오류 메시지를 출력하고 입력을 다시 받도록 수정하는 것이 좋습니다.
다음과 같이 수정해보세요:
except ValueError:
- raise ValueError(("잘못된 입력입니다"))
+ print("잘못된 입력입니다. 다시 입력해 주세요.")
+ continue📝 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.
| raise ValueError(("잘못된 입력입니다")) | |
| except ValueError: | |
| - raise ValueError(("잘못된 입력입니다")) | |
| + print("잘못된 입력입니다. 다시 입력해 주세요.") | |
| + continue |
🧰 Tools
🪛 Ruff (0.8.2)
15-15: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
Codecov ReportAttention: Patch coverage is
|
During the random number generation process, errors with number ranges from 1 to 8 have been corrected so that 1 to 9 operates normally
During the random number generation process, errors with number ranges from 1 to 8 have been corrected so that 1 to 9 operates normally
…he first number and returns immediately has been modified to check for duplicates in the entire array.
Summary by CodeRabbit