-
Notifications
You must be signed in to change notification settings - Fork 8
[자동차 경주] 김지성 과제 제출합니다. #3
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
|
""" Walkthrough이번 변경사항은 Python으로 구현된 자동차 경주 게임의 기능 명세와 실행 로직을 상세하게 정리하는 문서 업데이트와 함께, 게임의 핵심 기능을 구현하는 코드를 추가하는 내용입니다. README.md에서는 자동차 이름, 경주 횟수, 전진 로직, 우승 조건, 에러 처리 등 게임의 상세 요구사항을 명시하도록 재구성하였습니다. 또한, src/racingcar/main.py에는 이름 검증, 전진 결정, 상태 출력 및 승자 결정 함수가 새로 추가되어 메인 함수에서 사용자 입력을 받아 경주 시뮬레이션을 진행하도록 구현되었습니다. tests에서는 출력 캡처 방식을 개선했습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant U as 사용자
participant M as main()
participant C as check_carname()
participant F as carfoward()
participant S as status()
participant W as winner()
U->>M: 자동차 이름 및 경주 횟수 입력
M->>C: 자동차 이름 검증 요청
C-->>M: 유효 여부 반환 (ValueError 발생 가능)
loop 각 경주 시도마다
M->>F: 난수 기반 전진 결정 요청
F-->>M: 전진 결과 반환 (1 또는 0)
M->>S: 현재 상태 출력 요청
S-->>M: 상태 정보 출력
end
M->>W: 승자 결정 요청
W-->>M: 승자 정보 출력
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: 2
🔭 Outside diff range comments (2)
tests/racingcar/test_main.py (1)
26-36: 예외 처리 테스트 확장 필요현재는 자동차 이름에 대한 예외만 테스트하고 있습니다. 다음 예외 상황에 대한 테스트도 추가해야 합니다:
- 시도 횟수가 0인 경우
- 자동차 이름이 비어있는 경우
- 자동차 이름에 공백이 포함된 경우
🧰 Tools
🪛 Ruff (0.8.2)
32-34: Use a single
withstatement with multiple contexts instead of nestedwithstatements(SIM117)
README.md (1)
1-16: 요구사항 문서 개선 필요다음 사항들을 보완해야 합니다:
- 마크다운 형식 개선 (제목 레벨 사용)
- 입력값 예시 추가
- 출력 형식 상세 명시
- 에러 처리 케이스 구체화
-구현할 기능 목록 +# 자동차 경주 게임 + +## 구현할 기능 목록 + +### 자동차 이름 +- 경주할 자동차 이름을 쉼표(,)로 구분하여 입력 + - 예시: pobi,woni,jun +- 각 자동차 이름은 5글자 이하로 제한 + - 초과 시 ValueError 발생 +- 이름은 공백이나 빈 문자열일 수 없음 + +### 시행 횟수 +- 자연수로 입력 +- 0 입력 시 ValueError 발생 -자동차 이름 -- 경주할 자동차 이름(,구분) -- 각 자동차 이름 5글자로 제한 넘을 시 valueError +### 자동차 전진 +- 0-9 사이의 무작위 수를 생성하여 4 이상일 경우 전진 +- 현재 상태를 출력 + - 예시: + pobi : --- + woni : - + jun : -- -시행 횟수 -- 경주 시행 횟수 받기 +### 우승자 결정 +- 가장 멀리 이동한 자동차가 우승 +- 동률 발생 시 쉼표로 구분하여 모든 우승자 출력 + - 예시: 최종 우승자 : pobi, jun -자동차 전진 -- 자동차 전진(0,9 랜덤 수 중 4 넘으면 전진 아닐시 그대로 위치) -- 전지시 자동차 이름 출력 - -우승 조건 --경주 끝난 후 우승자 발표, 여러명일 시 쉼표 구분
🧹 Nitpick comments (4)
tests/racingcar/test_main.py (1)
9-24: 테스트 케이스 보완 필요기본적인 전진 및 정지 동작은 잘 테스트되어 있으나, 다음과 같은 추가 테스트 케이스가 필요합니다:
- 여러 대의 자동차가 동시에 우승하는 경우
- 최대 시도 횟수에 대한 테스트
- 자동차가 한 번도 전진하지 않는 경우
src/racingcar/main.py (3)
7-13: 전진 로직 가독성 개선 필요매직 넘버를 상수로 정의하고, 불필요한 else 문을 제거하여 코드의 가독성을 개선해야 합니다.
+FORWARD_THRESHOLD = 4 + def carfoward(): - a = random.randint(0,9) - if a >= 4: + move = random.randint(0, 9) + if move >= FORWARD_THRESHOLD: return 1 - else: - return 0 + return 0🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 7-7: Missing function or method docstring.
[warning] 9-9: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it.
🪛 GitHub Actions: Check PEP8 Style
[error] 7-7: E302 expected 2 blank lines, found 1
[error] 8-8: E225 missing whitespace around operator
[error] 8-8: E231 missing whitespace after ','
[error] 9-9: E225 missing whitespace around operator
[error] 9-9: E203 whitespace before ':'
[error] 11-11: E203 whitespace before ':'
14-17: 상태 출력 함수 개선 필요변수명을 파이썬 네이밍 컨벤션에 맞게 수정하고, f-string 사용 시 공백을 적절히 추가해야 합니다.
-def status(Cars): +def status(cars): - for key,value in Cars.items(): - print(f"{key} : {value*'-'}") + for name, distance in cars.items(): + print(f"{name} : {'-' * distance}")🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 14-14: Missing function or method docstring.
[warning] 14-14: Argument name 'Cars' doesn't conform to snake_case naming style.
🪛 GitHub Actions: Check PEP8 Style
[error] 14-14: E302 expected 2 blank lines, found 1
[error] 15-15: E231 missing whitespace after ','
20-25: 우승자 결정 로직 개선 필요변수명을 의미있게 수정하고, 공백을 일관성 있게 사용해야 합니다.
-def winner(Cars): - maxfoward=max(Cars.values()) - winners=[key for key,value in Cars.items() if value==maxfoward] - - print(f"\n최종 우승자 : {', '.join(winners)}") +def winner(cars): + max_distance = max(cars.values()) + winners = [ + name for name, distance in cars.items() + if distance == max_distance + ] + print(f"\n최종 우승자 : {', '.join(winners)}")🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 23-23: Trailing whitespace.
[warning] 20-20: Missing function or method docstring.
[warning] 20-20: Argument name 'Cars' doesn't conform to snake_case naming style.
🪛 GitHub Actions: Check PEP8 Style
[error] 20-20: E303 too many blank lines (3)
[error] 21-21: E225 missing whitespace around operator
[error] 22-22: E225 missing whitespace around operator
[error] 22-22: E231 missing whitespace after ','
[error] 22-22: E225 missing whitespace around operator
[warning] 23-23: W293 blank line contains whitespace
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md(1 hunks)src/racingcar/main.py(1 hunks)tests/racingcar/test_main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 34-34: src/racingcar/main.py#L34
Added line #L34 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 3-3: Bad indentation. Found 8 spaces, expected 4.
[warning] 4-4: Bad indentation. Found 12 spaces, expected 8.
[warning] 5-5: Bad indentation. Found 16 spaces, expected 12.
[warning] 23-23: Trailing whitespace.
[warning] 29-29: Trailing whitespace.
[warning] 31-31: Trailing whitespace.
[warning] 35-35: Trailing whitespace.
[warning] 43-43: Trailing whitespace.
[warning] 51-51: Trailing whitespace.
[warning] 52-52: Trailing whitespace.
[warning] 1-1: Missing module docstring.
[warning] 2-2: Missing function or method docstring.
[warning] 7-7: Missing function or method docstring.
[warning] 9-9: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it.
[warning] 14-14: Missing function or method docstring.
[warning] 14-14: Argument name 'Cars' doesn't conform to snake_case naming style.
[warning] 20-20: Missing function or method docstring.
[warning] 20-20: Argument name 'Cars' doesn't conform to snake_case naming style.
[warning] 26-26: Missing function or method docstring.
[warning] 30-30: Variable name 'Cars' doesn't conform to snake_case naming style.
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[error] 2-2: E302 expected 2 blank lines, found 0
[error] 3-3: E117 over-indented
[error] 3-3: E203 whitespace before ':'
[error] 4-4: E225 missing whitespace around operator
[error] 7-7: E302 expected 2 blank lines, found 1
[error] 8-8: E225 missing whitespace around operator
[error] 8-8: E231 missing whitespace after ','
[error] 9-9: E225 missing whitespace around operator
[error] 9-9: E203 whitespace before ':'
[error] 11-11: E203 whitespace before ':'
[error] 14-14: E302 expected 2 blank lines, found 1
[error] 15-15: E231 missing whitespace after ','
[error] 20-20: E303 too many blank lines (3)
[error] 21-21: E225 missing whitespace around operator
[error] 22-22: E225 missing whitespace around operator
[error] 22-22: E231 missing whitespace after ','
[error] 22-22: E225 missing whitespace around operator
[warning] 23-23: W293 blank line contains whitespace
[error] 26-26: E302 expected 2 blank lines, found 1
[error] 27-27: E225 missing whitespace around operator
[warning] 29-29: W293 blank line contains whitespace
[error] 30-30: E225 missing whitespace around operator
[error] 30-30: E231 missing whitespace after ','
[warning] 31-31: W293 blank line contains whitespace
[error] 32-32: E225 missing whitespace around operator
[error] 33-33: E225 missing whitespace around operator
[warning] 35-35: W293 blank line contains whitespace
[error] 36-36: E225 missing whitespace around operator
[error] 37-37: E225 missing whitespace around operator
[error] 39-39: E225 missing whitespace around operator
[error] 42-42: E225 missing whitespace around operator
[warning] 43-43: W293 blank line contains whitespace
[error] 45-45: E303 too many blank lines (2)
[warning] 51-51: W293 blank line contains whitespace
[warning] 52-52: W293 blank line contains whitespace
[error] 55-55: E303 too many blank lines (9)
| def main(): | ||
| """ | ||
| 프로그램의 진입점 함수. | ||
| 여기에서 전체 프로그램 로직을 시작합니다. | ||
| """ | ||
| # 프로그램의 메인 로직을 여기에 구현 | ||
| print("프로그램이 시작되었습니다.") | ||
| car_name=input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | ||
| check_carname(car_name) | ||
|
|
||
| Cars=dict.fromkeys(car_name,0) | ||
|
|
||
| trycount=int(input("시도할 횟수는 몇 회인가요?")) | ||
| if trycount ==0: | ||
| raise ValueError | ||
|
|
||
| count=0 | ||
| while count<trycount: | ||
| for i in car_name: | ||
| Cars[i]+=carfoward() | ||
| status(Cars) | ||
| print("") | ||
| count+=1 | ||
|
|
||
|
|
||
| winner(Cars) | ||
|
|
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
메인 함수 구조 개선 필요
다음과 같은 개선이 필요합니다:
- 입력 처리 로직을 별도 함수로 분리
- 변수명을 파이썬 컨벤션에 맞게 수정
- 적절한 에러 메시지 추가
- 공백과 들여쓰기 일관성 유지
+def get_car_names():
+ names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',')
+ check_carname(names)
+ return names
+
+def get_try_count():
+ count = int(input("시도할 횟수는 몇 회인가요?"))
+ if count == 0:
+ raise ValueError("시도 횟수는 0보다 커야 합니다.")
+ return count
+
def main():
- car_name=input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',')
- check_carname(car_name)
-
- Cars=dict.fromkeys(car_name,0)
-
- trycount=int(input("시도할 횟수는 몇 회인가요?"))
- if trycount ==0:
- raise ValueError
-
- count=0
- while count<trycount:
- for i in car_name:
- Cars[i]+=carfoward()
- status(Cars)
- print("")
- count+=1
-
-
- winner(Cars)
+ try:
+ car_names = get_car_names()
+ cars = dict.fromkeys(car_names, 0)
+ try_count = get_try_count()
+
+ for _ in range(try_count):
+ for name in car_names:
+ cars[name] += carfoward()
+ status(cars)
+ print()
+
+ winner(cars)
+ except ValueError as e:
+ print(f"오류: {str(e)}")🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 34-34: src/racingcar/main.py#L34
Added line #L34 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
[warning] 29-29: Trailing whitespace.
[warning] 31-31: Trailing whitespace.
[warning] 35-35: Trailing whitespace.
[warning] 43-43: Trailing whitespace.
[warning] 26-26: Missing function or method docstring.
[warning] 30-30: Variable name 'Cars' doesn't conform to snake_case naming style.
🪛 GitHub Actions: Check PEP8 Style
[error] 26-26: E302 expected 2 blank lines, found 1
[error] 27-27: E225 missing whitespace around operator
[warning] 29-29: W293 blank line contains whitespace
[error] 30-30: E225 missing whitespace around operator
[error] 30-30: E231 missing whitespace after ','
[warning] 31-31: W293 blank line contains whitespace
[error] 32-32: E225 missing whitespace around operator
[error] 33-33: E225 missing whitespace around operator
[warning] 35-35: W293 blank line contains whitespace
[error] 36-36: E225 missing whitespace around operator
[error] 37-37: E225 missing whitespace around operator
[error] 39-39: E225 missing whitespace around operator
[error] 42-42: E225 missing whitespace around operator
[warning] 43-43: W293 blank line contains whitespace
[error] 45-45: E303 too many blank lines (2)
src/racingcar/main.py
Outdated
| def check_carname(x): | ||
| for i in x : | ||
| if len(i)>5: | ||
| 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.
🛠️ Refactor suggestion
자동차 이름 검증 로직 개선 필요
현재 구현은 기본적인 길이 검증만 수행합니다. 다음 사항들을 추가로 검증해야 합니다:
- 빈 문자열 체크
- 공백 문자 포함 여부 체크
- 중복된 이름 체크
def check_carname(x):
+ if not x:
+ raise ValueError("자동차 이름은 비어있을 수 없습니다.")
for i in x:
+ if not i.strip():
+ raise ValueError("자동차 이름은 공백일 수 없습니다.")
if len(i) > 5:
- raise ValueError
+ raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.")
+ if len(x) != len(set(x)):
+ raise ValueError("자동차 이름은 중복될 수 없습니다.")📝 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.
| def check_carname(x): | |
| for i in x : | |
| if len(i)>5: | |
| raise ValueError | |
| def check_carname(x): | |
| if not x: | |
| raise ValueError("자동차 이름은 비어있을 수 없습니다.") | |
| for i in x: | |
| if not i.strip(): | |
| raise ValueError("자동차 이름은 공백일 수 없습니다.") | |
| if len(i) > 5: | |
| raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") | |
| if len(x) != len(set(x)): | |
| raise ValueError("자동차 이름은 중복될 수 없습니다.") |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 3-3: Bad indentation. Found 8 spaces, expected 4.
[warning] 4-4: Bad indentation. Found 12 spaces, expected 8.
[warning] 5-5: Bad indentation. Found 16 spaces, expected 12.
[warning] 2-2: Missing function or method docstring.
🪛 GitHub Actions: Check PEP8 Style
[error] 2-2: E302 expected 2 blank lines, found 0
[error] 3-3: E117 over-indented
[error] 3-3: E203 whitespace before ':'
[error] 4-4: E225 missing whitespace around operator
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
♻️ Duplicate comments (2)
src/racingcar/main.py (2)
4-10:⚠️ Potential issue자동차 이름 검증 로직 개선 필요
현재 구현은 기본적인 길이 검증만 수행합니다. 다음 사항들을 추가로 검증해야 합니다:
- 빈 문자열 체크
- 공백 문자 포함 여부 체크
- 중복된 이름 체크
다음과 같이 개선하세요:
def check_carname(x): ''' 이름 검증 절차 ''' + if not x: + raise ValueError("자동차 이름은 비어있을 수 없습니다.") for i in x: + if not i.strip(): + raise ValueError("자동차 이름은 공백일 수 없습니다.") if len(i) > 5: raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") + if len(x) != len(set(x)): + raise ValueError("자동차 이름은 중복될 수 없습니다.")🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 8-8: E203 whitespace before ':'
[error] 9-9: E225 missing whitespace around operator
39-65:⚠️ Potential issue메인 함수 구조 개선 필요
다음과 같은 개선이 필요합니다:
- 입력 처리 로직을 별도 함수로 분리
- 변수명을 파이썬 컨벤션에 맞게 수정
- 적절한 에러 처리 추가
- 공백과 들여쓰기 일관성 유지
다음과 같이 개선하세요:
+def get_car_names(): + names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') + check_carname(names) + return names + +def get_try_count(): + try: + count = int(input("시도할 횟수는 몇 회인가요?")) + if count <= 0: + raise ValueError("시도 횟수는 0보다 커야 합니다.") + return count + except ValueError as e: + raise ValueError("시도 횟수는 숫자여야 합니다.") from e + def main(): - car_name=input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') - check_carname(car_name) - - Cars=dict.fromkeys(car_name,0) - - trycount=int(input("시도할 횟수는 몇 회인가요?")) - if trycount ==0: - ValueError("시도할 횟수는 0일 수 없습니다") - - count=0 - while count<trycount: - for i in car_name: - Cars[i]+=carfoward() - status(Cars) - print("") - count+=1 - - - winner(Cars) + try: + car_names = get_car_names() + cars = dict.fromkeys(car_names, 0) + try_count = get_try_count() + + for _ in range(try_count): + for name in car_names: + cars[name] += car_forward() + status(cars) + print() + + winner(cars) + except ValueError as e: + print(f"오류: {str(e)}")🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 47-47: src/racingcar/main.py#L47
Added line #L47 was not covered by tests🪛 GitHub Actions: Check Indentation Depth
[warning] 42-42: Trailing whitespace (trailing-whitespace)
[warning] 44-44: Trailing whitespace (trailing-whitespace)
[warning] 48-48: Trailing whitespace (trailing-whitespace)
[warning] 56-56: Trailing whitespace (trailing-whitespace)
[warning] 64-64: Trailing whitespace (trailing-whitespace)
[warning] 65-65: Trailing whitespace (trailing-whitespace)
[warning] 39-39: Missing function or method docstring (missing-function-docstring)
[warning] 43-43: Variable name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 47-47: Exception statement has no effect (pointless-exception-statement)
🪛 GitHub Actions: Check PEP8 Style
[error] 39-39: E302 expected 2 blank lines, found 1
[error] 40-40: E225 missing whitespace around operator
[warning] 42-42: W293 blank line contains whitespace
[error] 43-43: E225 missing whitespace around operator
[error] 43-43: E231 missing whitespace after ','
[warning] 44-44: W293 blank line contains whitespace
[error] 45-45: E225 missing whitespace around operator
[error] 46-46: E225 missing whitespace around operator
[warning] 48-48: W293 blank line contains whitespace
[error] 49-49: E225 missing whitespace around operator
[error] 50-50: E225 missing whitespace around operator
[error] 52-52: E225 missing whitespace around operator
[error] 55-55: E225 missing whitespace around operator
[warning] 56-56: W293 blank line contains whitespace
[error] 58-58: E303 too many blank lines (2)
[warning] 64-64: W293 blank line contains whitespace
[warning] 65-65: W293 blank line contains whitespace
🧹 Nitpick comments (1)
src/racingcar/main.py (1)
1-3: 모듈 문서화 및 구조 개선 필요모듈의 목적과 기능을 설명하는 문서화가 필요합니다.
다음과 같이 개선하세요:
import random - - +""" +자동차 경주 게임을 구현한 모듈입니다. +사용자로부터 자동차 이름과 시도 횟수를 입력받아 경주를 진행하고 우승자를 결정합니다. +"""🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 1-1: Missing module docstring (missing-module-docstring)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 47-47: src/racingcar/main.py#L47
Added line #L47 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 42-42: Trailing whitespace (trailing-whitespace)
[warning] 44-44: Trailing whitespace (trailing-whitespace)
[warning] 48-48: Trailing whitespace (trailing-whitespace)
[warning] 56-56: Trailing whitespace (trailing-whitespace)
[warning] 64-64: Trailing whitespace (trailing-whitespace)
[warning] 65-65: Trailing whitespace (trailing-whitespace)
[warning] 1-1: Missing module docstring (missing-module-docstring)
[warning] 17-17: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it (no-else-return)
[warning] 22-22: Argument name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 31-31: Argument name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 39-39: Missing function or method docstring (missing-function-docstring)
[warning] 43-43: Variable name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 47-47: Exception statement has no effect (pointless-exception-statement)
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[error] 8-8: E203 whitespace before ':'
[error] 9-9: E225 missing whitespace around operator
[error] 12-12: E302 expected 2 blank lines, found 1
[error] 16-16: E225 missing whitespace around operator
[error] 16-16: E231 missing whitespace after ','
[error] 17-17: E225 missing whitespace around operator
[error] 17-17: E203 whitespace before ':'
[error] 19-19: E203 whitespace before ':'
[error] 22-22: E302 expected 2 blank lines, found 1
[error] 26-26: E231 missing whitespace after ','
[error] 31-31: E303 too many blank lines (3)
[error] 35-35: E225 missing whitespace around operator
[error] 36-36: E225 missing whitespace around operator
[error] 36-36: E231 missing whitespace after ','
[error] 36-36: E225 missing whitespace around operator
[error] 39-39: E302 expected 2 blank lines, found 1
[error] 40-40: E225 missing whitespace around operator
[warning] 42-42: W293 blank line contains whitespace
[error] 43-43: E225 missing whitespace around operator
[error] 43-43: E231 missing whitespace after ','
[warning] 44-44: W293 blank line contains whitespace
[error] 45-45: E225 missing whitespace around operator
[error] 46-46: E225 missing whitespace around operator
[warning] 48-48: W293 blank line contains whitespace
[error] 49-49: E225 missing whitespace around operator
[error] 50-50: E225 missing whitespace around operator
[error] 52-52: E225 missing whitespace around operator
[error] 55-55: E225 missing whitespace around operator
[warning] 56-56: W293 blank line contains whitespace
[error] 58-58: E303 too many blank lines (2)
[warning] 64-64: W293 blank line contains whitespace
[warning] 65-65: W293 blank line contains whitespace
[error] 68-68: E303 too many blank lines (9)
🔇 Additional comments (1)
src/racingcar/main.py (1)
1-71: undefined🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 47-47: src/racingcar/main.py#L47
Added line #L47 was not covered by tests🪛 GitHub Actions: Check Indentation Depth
[warning] 42-42: Trailing whitespace (trailing-whitespace)
[warning] 44-44: Trailing whitespace (trailing-whitespace)
[warning] 48-48: Trailing whitespace (trailing-whitespace)
[warning] 56-56: Trailing whitespace (trailing-whitespace)
[warning] 64-64: Trailing whitespace (trailing-whitespace)
[warning] 65-65: Trailing whitespace (trailing-whitespace)
[warning] 1-1: Missing module docstring (missing-module-docstring)
[warning] 17-17: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it (no-else-return)
[warning] 22-22: Argument name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 31-31: Argument name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 39-39: Missing function or method docstring (missing-function-docstring)
[warning] 43-43: Variable name 'Cars' doesn't conform to snake_case naming style (invalid-name)
[warning] 47-47: Exception statement has no effect (pointless-exception-statement)
🪛 GitHub Actions: Check PEP8 Style
[error] 8-8: E203 whitespace before ':'
[error] 9-9: E225 missing whitespace around operator
[error] 12-12: E302 expected 2 blank lines, found 1
[error] 16-16: E225 missing whitespace around operator
[error] 16-16: E231 missing whitespace after ','
[error] 17-17: E225 missing whitespace around operator
[error] 17-17: E203 whitespace before ':'
[error] 19-19: E203 whitespace before ':'
[error] 22-22: E302 expected 2 blank lines, found 1
[error] 26-26: E231 missing whitespace after ','
[error] 31-31: E303 too many blank lines (3)
[error] 35-35: E225 missing whitespace around operator
[error] 36-36: E225 missing whitespace around operator
[error] 36-36: E231 missing whitespace after ','
[error] 36-36: E225 missing whitespace around operator
[error] 39-39: E302 expected 2 blank lines, found 1
[error] 40-40: E225 missing whitespace around operator
[warning] 42-42: W293 blank line contains whitespace
[error] 43-43: E225 missing whitespace around operator
[error] 43-43: E231 missing whitespace after ','
[warning] 44-44: W293 blank line contains whitespace
[error] 45-45: E225 missing whitespace around operator
[error] 46-46: E225 missing whitespace around operator
[warning] 48-48: W293 blank line contains whitespace
[error] 49-49: E225 missing whitespace around operator
[error] 50-50: E225 missing whitespace around operator
[error] 52-52: E225 missing whitespace around operator
[error] 55-55: E225 missing whitespace around operator
[warning] 56-56: W293 blank line contains whitespace
[error] 58-58: E303 too many blank lines (2)
[warning] 64-64: W293 blank line contains whitespace
[warning] 65-65: W293 blank line contains whitespace
[error] 68-68: E303 too many blank lines (9)
src/racingcar/main.py
Outdated
| def status(Cars): | ||
| """ | ||
| 진행상태를 나타내는 함수 | ||
| """ | ||
| for key,value in Cars.items(): | ||
| print(f"{key} : {value*'-'}") | ||
|
|
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
변수명 및 코드 스타일 개선 필요
파이썬 명명 규칙(snake_case)을 따르도록 개선이 필요합니다.
다음과 같이 개선하세요:
-def status(Cars):
+def status(cars):
"""
진행상태를 나타내는 함수
"""
- for key,value in Cars.items():
+ for key, value in cars.items():
print(f"{key} : {value*'-'}")📝 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.
| def status(Cars): | |
| """ | |
| 진행상태를 나타내는 함수 | |
| """ | |
| for key,value in Cars.items(): | |
| print(f"{key} : {value*'-'}") | |
| def status(cars): | |
| """ | |
| 진행상태를 나타내는 함수 | |
| """ | |
| for key, value in cars.items(): | |
| print(f"{key} : {value*'-'}") |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 22-22: Argument name 'Cars' doesn't conform to snake_case naming style (invalid-name)
🪛 GitHub Actions: Check PEP8 Style
[error] 22-22: E302 expected 2 blank lines, found 1
[error] 26-26: E231 missing whitespace after ','
src/racingcar/main.py
Outdated
| def carfoward(): | ||
| """ | ||
| 자동차 전진시키는 함수수 | ||
| """ | ||
| a=random.randint(0,9) | ||
| if a>=4 : | ||
| return 1 | ||
| else : | ||
| return 0 |
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
함수 이름 및 구현 개선 필요
함수 이름에 오타가 있으며, 코드 스타일 개선이 필요합니다.
다음과 같이 개선하세요:
-def carfoward():
+def car_forward():
"""
- 자동차 전진시키는 함수수
+ 자동차 전진시키는 함수
"""
- a=random.randint(0,9)
- if a>=4 :
+ random_number = random.randint(0, 9)
+ if random_number >= 4:
return 1
- else :
- return 0
+ return 0📝 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.
| def carfoward(): | |
| """ | |
| 자동차 전진시키는 함수수 | |
| """ | |
| a=random.randint(0,9) | |
| if a>=4 : | |
| return 1 | |
| else : | |
| return 0 | |
| def car_forward(): | |
| """ | |
| 자동차 전진시키는 함수 | |
| """ | |
| random_number = random.randint(0, 9) | |
| if random_number >= 4: | |
| return 1 | |
| return 0 |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 17-17: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it (no-else-return)
🪛 GitHub Actions: Check PEP8 Style
[error] 12-12: E302 expected 2 blank lines, found 1
[error] 16-16: E225 missing whitespace around operator
[error] 16-16: E231 missing whitespace after ','
[error] 17-17: E225 missing whitespace around operator
[error] 17-17: E203 whitespace before ':'
[error] 19-19: E203 whitespace before ':'
src/racingcar/main.py
Outdated
| def winner(Cars): | ||
| """ | ||
| 프로그램의 진입점 함수. | ||
| 여기에서 전체 프로그램 로직을 시작합니다. | ||
| 최종 우승자를 나타내는 함수 | ||
| """ | ||
| # 프로그램의 메인 로직을 여기에 구현 | ||
| print("프로그램이 시작되었습니다.") | ||
| maxfoward=max(Cars.values()) | ||
| winners=[key for key,value in Cars.items() if value==maxfoward] | ||
| print(f"\n최종 우승자 : {', '.join(winners)}") |
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
변수명 및 코드 스타일 개선 필요
파이썬 명명 규칙(snake_case)을 따르도록 개선이 필요합니다.
다음과 같이 개선하세요:
-def winner(Cars):
+def winner(cars):
"""
최종 우승자를 나타내는 함수
"""
- maxfoward=max(Cars.values())
- winners=[key for key,value in Cars.items() if value==maxfoward]
+ max_forward = max(cars.values())
+ winners = [key for key, value in cars.items() if value == max_forward]
print(f"\n최종 우승자 : {', '.join(winners)}")📝 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.
| def winner(Cars): | |
| """ | |
| 프로그램의 진입점 함수. | |
| 여기에서 전체 프로그램 로직을 시작합니다. | |
| 최종 우승자를 나타내는 함수 | |
| """ | |
| # 프로그램의 메인 로직을 여기에 구현 | |
| print("프로그램이 시작되었습니다.") | |
| maxfoward=max(Cars.values()) | |
| winners=[key for key,value in Cars.items() if value==maxfoward] | |
| print(f"\n최종 우승자 : {', '.join(winners)}") | |
| def winner(cars): | |
| """ | |
| 최종 우승자를 나타내는 함수 | |
| """ | |
| max_forward = max(cars.values()) | |
| winners = [key for key, value in cars.items() if value == max_forward] | |
| print(f"\n최종 우승자 : {', '.join(winners)}") |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 31-31: Argument name 'Cars' doesn't conform to snake_case naming style (invalid-name)
🪛 GitHub Actions: Check PEP8 Style
[error] 31-31: E303 too many blank lines (3)
[error] 35-35: E225 missing whitespace around operator
[error] 36-36: E225 missing whitespace around operator
[error] 36-36: E231 missing whitespace after ','
[error] 36-36: E225 missing whitespace around operator
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: 2
♻️ Duplicate comments (2)
src/racingcar/main.py (2)
4-10: 🛠️ Refactor suggestion자동차 이름 검증 로직 개선 필요
현재 구현은 길이 검증만 수행하고 있습니다. 이전 리뷰에서 지적된 다음 사항들을 추가로 검증해야 합니다:
def check_carname(x): - ''' - 이름 검증 절차 - ''' + """ + 자동차 이름의 유효성을 검증하는 함수 + + Args: + x (list): 검증할 자동차 이름 리스트 + + Raises: + ValueError: 이름이 유효하지 않은 경우 + """ + if not x: + raise ValueError("자동차 이름은 비어있을 수 없습니다.") for i in x: + if not i.strip(): + raise ValueError("자동차 이름은 공백일 수 없습니다.") if len(i) > 5: raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") + if len(x) != len(set(x)): + raise ValueError("자동차 이름은 중복될 수 없습니다.")
13-21: 🛠️ Refactor suggestion함수 이름 및 구현 개선 필요
함수 이름에 오타가 있으며, 코드 구조와 변수명을 개선해야 합니다.
-def carfoward(): +def car_forward(): """ 자동차 전진시키는 함수 + + Returns: + int: 전진 시 1, 정지 시 0을 반환 """ - a = random.randint(0, 9) - if a >= 4: + random_number = random.randint(0, 9) + if random_number >= 4: return 1 - else: - return 0 + return 0🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 18-18: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it
🧹 Nitpick comments (1)
src/racingcar/main.py (1)
24-29: 함수 문서화 개선 필요현재 문서화가 불충분합니다. 매개변수와 출력 형식에 대한 설명이 필요합니다.
def status(cars): """ - 진행상태를 나타내는 함수 + 각 자동차의 현재 진행 상태를 출력하는 함수 + + Args: + cars (dict): 자동차 이름을 키로 하고 진행 거리를 값으로 하는 딕셔너리 + + 출력 형식: + 자동차이름 : ----- (진행 거리만큼 '-' 표시) """ for key, value in cars.items(): print(f"{key} : {value * '-'}")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 44-44: Trailing whitespace
[warning] 46-46: Trailing whitespace
[warning] 50-50: Trailing whitespace
[warning] 58-58: Trailing whitespace
[warning] 1-1: Missing module docstring
[warning] 18-18: Unnecessary 'else' after 'return', remove the 'else' and de-indent the code inside it
[warning] 41-41: Missing function or method docstring
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[warning] 44-44: Blank line contains whitespace.
[warning] 46-46: Blank line contains whitespace.
[warning] 50-50: Blank line contains whitespace.
[warning] 58-58: Blank line contains whitespace.
🔇 Additional comments (2)
src/racingcar/main.py (2)
62-64: LGTM!메인 가드가 올바르게 구현되어 있습니다.
32-38: 🛠️ Refactor suggestion변수명 및 문서화 개선 필요
변수명이 Python 명명 규칙을 따르지 않으며, 문서화가 불충분합니다.
def winner(cars): """ - 최종 우승자를 나타내는 함수 + 가장 멀리 이동한 자동차들을 우승자로 선정하여 출력하는 함수 + + Args: + cars (dict): 자동차 이름을 키로 하고 진행 거리를 값으로 하는 딕셔너리 """ - maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_distance = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_distance] print(f"\n최종 우승자 : {', '.join(winners)}")Likely invalid or redundant comment.
| import random | ||
|
|
||
|
|
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
모듈 수준의 문서화 및 구조화 필요
모듈의 목적과 기능을 설명하는 docstring이 누락되었습니다. 또한 불필요한 빈 줄이 있습니다.
다음과 같이 개선하세요:
import random
-
-
+"""
+자동차 경주 게임을 구현한 모듈입니다.
+이 모듈은 사용자로부터 자동차 이름과 시도 횟수를 입력받아
+랜덤한 전진 로직에 따라 경주를 진행하고 우승자를 결정합니다.
+"""📝 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 | |
| import random | |
| """ | |
| 자동차 경주 게임을 구현한 모듈입니다. | |
| 이 모듈은 사용자로부터 자동차 이름과 시도 횟수를 입력받아 | |
| 랜덤한 전진 로직에 따라 경주를 진행하고 우승자를 결정합니다. | |
| """ |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 1-1: Missing module docstring
src/racingcar/main.py
Outdated
| car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | ||
| check_carname(car_name) | ||
|
|
||
| cars = dict.fromkeys(car_name, 0) | ||
|
|
||
| trycount = int(input("시도할 횟수는 몇 회인가요?")) | ||
| if trycount == 0: | ||
| raise ValueError("시도할 횟수는 0일 수 없습니다") | ||
|
|
||
| count = 0 | ||
| while count < trycount: | ||
| for i in car_name: | ||
| cars[i] += carfoward() | ||
| status(cars) | ||
| print("") | ||
| count += 1 | ||
|
|
||
| winner(cars) | ||
|
|
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
메인 함수 구조 개선 필요
함수가 문서화되어 있지 않으며, 코드 구조와 에러 처리를 개선할 수 있습니다.
def main():
+ """
+ 자동차 경주 게임의 메인 함수
+
+ 사용자로부터 자동차 이름과 시도 횟수를 입력받아 경주를 진행하고
+ 결과를 출력합니다.
+ """
- car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',')
- check_carname(car_name)
-
- cars = dict.fromkeys(car_name, 0)
-
- trycount = int(input("시도할 횟수는 몇 회인가요?"))
- if trycount == 0:
- raise ValueError("시도할 횟수는 0일 수 없습니다")
-
- count = 0
- while count < trycount:
- for i in car_name:
- cars[i] += carfoward()
- status(cars)
- print("")
- count += 1
-
- winner(cars)
+ try:
+ car_names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',')
+ check_carname(car_names)
+
+ cars = dict.fromkeys(car_names, 0)
+
+ try_count = int(input("시도할 횟수는 몇 회인가요?"))
+ if try_count <= 0:
+ raise ValueError("시도 횟수는 0보다 커야 합니다.")
+
+ for _ in range(try_count):
+ for name in car_names:
+ cars[name] += car_forward()
+ status(cars)
+ print()
+
+ winner(cars)
+ except ValueError as e:
+ print(f"오류: {str(e)}")
+ except Exception as e:
+ print(f"예상치 못한 오류가 발생했습니다: {str(e)}")📝 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.
| def main(): | |
| car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | |
| check_carname(car_name) | |
| cars = dict.fromkeys(car_name, 0) | |
| trycount = int(input("시도할 횟수는 몇 회인가요?")) | |
| if trycount == 0: | |
| raise ValueError("시도할 횟수는 0일 수 없습니다") | |
| count = 0 | |
| while count < trycount: | |
| for i in car_name: | |
| cars[i] += carfoward() | |
| status(cars) | |
| print("") | |
| count += 1 | |
| winner(cars) | |
| def main(): | |
| """ | |
| 자동차 경주 게임의 메인 함수 | |
| 사용자로부터 자동차 이름과 시도 횟수를 입력받아 경주를 진행하고 | |
| 결과를 출력합니다. | |
| """ | |
| try: | |
| car_names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | |
| check_carname(car_names) | |
| cars = dict.fromkeys(car_names, 0) | |
| try_count = int(input("시도할 횟수는 몇 회인가요?")) | |
| if try_count <= 0: | |
| raise ValueError("시도 횟수는 0보다 커야 합니다.") | |
| for _ in range(try_count): | |
| for name in car_names: | |
| cars[name] += car_forward() | |
| status(cars) | |
| print() | |
| winner(cars) | |
| except ValueError as e: | |
| print(f"오류: {str(e)}") | |
| except Exception as e: | |
| print(f"예상치 못한 오류가 발생했습니다: {str(e)}") |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 44-44: Trailing whitespace
[warning] 46-46: Trailing whitespace
[warning] 50-50: Trailing whitespace
[warning] 58-58: Trailing whitespace
[warning] 41-41: Missing function or method docstring
🪛 GitHub Actions: Check PEP8 Style
[warning] 44-44: Blank line contains whitespace.
[warning] 46-46: Blank line contains whitespace.
[warning] 50-50: Blank line contains whitespace.
[warning] 58-58: Blank line contains whitespace.
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 (4)
src/racingcar/main.py (4)
7-14: 🛠️ Refactor suggestion자동차 이름 검증 로직 개선 필요
현재 구현은 길이 검증만 수행하고 있습니다. 다음 사항들을 추가로 검증해야 합니다:
- 빈 입력값 체크
- 공백 문자 포함 여부 체크
- 중복된 이름 체크
- 매개변수 이름을 더 명확하게 변경
-def check_carname(x): +def check_carname(car_names): ''' 자동차 이름을 검증하는 함수. 이름이 5자를 초과할 경우 예외를 발생시킨다. ''' + if not car_names: + raise ValueError("자동차 이름이 입력되지 않았습니다.") + + if len(car_names) != len(set(car_names)): + raise ValueError("자동차 이름은 중복될 수 없습니다.") + for i in x: + if not i.strip(): + raise ValueError("자동차 이름은 공백일 수 없습니다.") if len(i) > 5: raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.")🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 7-7: E302 expected 2 blank lines, found 1
16-24: 🛠️ Refactor suggestion함수 이름 및 변수명 개선 필요
다음과 같은 개선이 필요합니다:
- 함수 이름의 오타 수정 (carfoward → car_forward)
- 변수명을 더 명확하게 변경 (a → random_number)
-def carfoward(): +def car_forward(): """ 자동차를 전진시키는 함수. 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. """ - a = random.randint(0, 9) - if a >= 4: + random_number = random.randint(0, 9) + if random_number >= 4: return 1 return 0🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 16-16: E302 expected 2 blank lines, found 1
34-41: 🛠️ Refactor suggestion변수명 개선 필요
Python 명명 규칙(snake_case)을 따르도록 개선이 필요합니다:
- maxfoward → max_forward
def winner(cars): """ 최종 우승자를 출력하는 함수. 가장 많은 전진을 한 자동차들을 우승자로 표시한다. """ - maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_forward = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_forward] print(f"\n최종 우승자 : {', '.join(winners)}")🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 34-34: E302 expected 2 blank lines, found 1
43-61: 🛠️ Refactor suggestion메인 함수 구조 개선 필요
다음과 같은 개선이 필요합니다:
- 함수 문서화 추가
- 예외 처리 추가
- while 루프를 for 루프로 변경
- 변수명을 Python 명명 규칙에 맞게 수정
def main(): + """ + 자동차 경주 게임의 메인 함수입니다. + + 사용자로부터 자동차 이름과 시도 횟수를 입력받아 + 경주를 진행하고 결과를 출력합니다. + """ + try: car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') check_carname(car_name) cars = dict.fromkeys(car_name, 0) - trycount = int(input("시도할 횟수는 몇 회인가요?")) - if trycount == 0: + try_count = int(input("시도할 횟수는 몇 회인가요?")) + if try_count <= 0: raise ValueError("시도할 횟수는 0일 수 없습니다") - count = 0 - while count < trycount: - for i in car_name: - cars[i] += carfoward() + for _ in range(try_count): + for name in car_name: + cars[name] += car_forward() status(cars) print("") - count += 1 winner(cars) + except ValueError as e: + print(f"오류: {str(e)}") + except Exception as e: + print(f"예상치 못한 오류가 발생했습니다: {str(e)}")🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 51-51: src/racingcar/main.py#L51
Added line #L51 was not covered by tests🪛 GitHub Actions: Check Indentation Depth
[warning] 46-46: Trailing whitespace
[warning] 48-48: Trailing whitespace
[warning] 52-52: Trailing whitespace
[warning] 60-60: Trailing whitespace
[warning] 43-43: Missing function or method docstring
🪛 GitHub Actions: Check PEP8 Style
[error] 43-43: E302 expected 2 blank lines, found 1
[warning] 46-46: W293 blank line contains whitespace
[warning] 48-48: W293 blank line contains whitespace
[warning] 52-52: W293 blank line contains whitespace
[warning] 60-60: W293 blank line contains whitespace
🧹 Nitpick comments (1)
src/racingcar/main.py (1)
1-5: 모듈 문서화 개선 필요다음과 같은 개선이 필요합니다:
- 작은따옴표(') 대신 큰따옴표(")를 사용하여 docstring 작성
- 모듈의 목적과 주요 기능을 상세히 설명
import random -''' -자동차 경주 프로그램 -''' +""" +자동차 경주 게임을 구현한 모듈입니다. + +이 모듈은 다음과 같은 기능을 제공합니다: +- 사용자로부터 자동차 이름과 시도 횟수 입력 받기 +- 랜덤한 전진 로직에 따라 경주 진행 +- 경주 상태 출력 +- 우승자 결정 및 발표 +"""🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 1-1: Missing module docstring
[warning] 3-3: String statement has no effect
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 51-51: src/racingcar/main.py#L51
Added line #L51 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 46-46: Trailing whitespace
[warning] 48-48: Trailing whitespace
[warning] 52-52: Trailing whitespace
[warning] 60-60: Trailing whitespace
[warning] 1-1: Missing module docstring
[warning] 3-3: String statement has no effect
[warning] 43-43: Missing function or method docstring
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[error] 7-7: E302 expected 2 blank lines, found 1
[error] 16-16: E302 expected 2 blank lines, found 1
[error] 26-26: E302 expected 2 blank lines, found 1
[error] 34-34: E302 expected 2 blank lines, found 1
[error] 43-43: E302 expected 2 blank lines, found 1
[warning] 46-46: W293 blank line contains whitespace
[warning] 48-48: W293 blank line contains whitespace
[warning] 52-52: W293 blank line contains whitespace
[warning] 60-60: W293 blank line contains whitespace
🔇 Additional comments (2)
src/racingcar/main.py (2)
26-32: 구현이 깔끔합니다!상태 출력 함수가 명확하게 구현되어 있습니다.
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 26-26: E302 expected 2 blank lines, found 1
50-51: 시도 횟수가 0인 경우에 대한 테스트 케이스 필요시도 횟수 검증 로직에 대한 테스트 케이스가 누락되어 있습니다.
테스트 케이스를 추가하여 예외 처리가 정상적으로 동작하는지 확인해 주세요.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 51-51: src/racingcar/main.py#L51
Added line #L51 was not covered by tests
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 (3)
src/racingcar/main.py (3)
1-7: 모듈 문서화가 잘 되어있으나 포맷팅 개선 필요모듈의 목적과 기능이 명확하게 설명되어 있습니다. 다만 다음과 같은 스타일 개선이 필요합니다:
- 불필요한 빈 줄 제거
- 후행 공백 제거
다음과 같이 수정하세요:
import random - """ -자동차 경주 프로그램 -이 모듈은 간단한 자동차 경주 게임을 구현합니다. 사용자로부터 자동차 이름을 입력받고, -정해진 횟수만큼 자동차가 전진하는 시뮬레이션을 진행하여 최종 우승자를 출력합니다. +자동차 경주 프로그램 + +이 모듈은 간단한 자동차 경주 게임을 구현합니다. 사용자로부터 자동차 이름을 입력받고, +정해진 횟수만큼 자동차가 전진하는 시뮬레이션을 진행하여 최종 우승자를 출력합니다. """🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[warning] 5-5: trailing whitespace
🪛 GitHub Actions: Check Indentation Depth
[warning] 1-1: Missing module docstring
[warning] 3-3: String statement has no effect
19-27: 함수명과 변수명 개선 필요다음과 같은 개선이 필요합니다:
- 함수명 오타 수정 (
carfoward→car_forward)- 변수명을 더 명확하게 수정 (
a→random_number)다음과 같이 수정하세요:
-def carfoward(): +def car_forward(): """ 자동차를 전진시키는 함수. 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. """ - a = random.randint(0, 9) - if a >= 4: + random_number = random.randint(0, 9) + if random_number >= 4: return 1 return 0
39-46: 변수명을 Python 명명 규칙에 맞게 수정 필요다음과 같은 개선이 필요합니다:
- 변수명을 snake_case로 수정 (
maxfoward→max_forward)다음과 같이 수정하세요:
def winner(cars): """ 최종 우승자를 출력하는 함수. 가장 많은 전진을 한 자동차들을 우승자로 표시한다. """ - maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_forward = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_forward] print(f"\n최종 우승자 : {', '.join(winners)}")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 61-61: src/racingcar/main.py#L61
Added line #L61 was not covered by tests
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[warning] 5-5: trailing whitespace
[error] 9-9: expected 2 blank lines, found 1
[warning] 56-56: blank line contains whitespace
[warning] 58-58: blank line contains whitespace
[warning] 62-62: blank line contains whitespace
[warning] 70-70: blank line contains whitespace
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 56-56: Trailing whitespace
[warning] 58-58: Trailing whitespace
[warning] 62-62: Trailing whitespace
[warning] 70-70: Trailing whitespace
[warning] 1-1: Missing module docstring
[warning] 3-3: String statement has no effect
🔇 Additional comments (4)
src/racingcar/main.py (4)
30-36: 구현이 깔끔합니다!상태 출력 함수가 명확하게 구현되어 있고 문서화도 잘 되어 있습니다.
60-61: 시도 횟수 검증에 대한 테스트 케이스 필요시도 횟수가 0인 경우에 대한 예외 처리 코드가 테스트되지 않았습니다.
테스트 케이스를 추가하여 예외 처리 로직을 검증해야 합니다. 테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 61-61: src/racingcar/main.py#L61
Added line #L61 was not covered by tests
9-17: 🛠️ Refactor suggestion자동차 이름 검증 로직 보완 필요
현재는 이름 길이만 검증하고 있습니다. 다음 검증을 추가해야 합니다:
- 빈 입력값 검증
- 공백만 있는 이름 검증
- 중복된 이름 검증
다음과 같이 개선하세요:
def check_carname(x): ''' 자동차 이름을 검증하는 함수. - 이름이 5자를 초과할 경우 예외를 발생시킨다. + 다음 조건을 검증하여 위반시 예외를 발생시킨다: + - 이름이 5자를 초과하는 경우 + - 이름이 비어있거나 공백인 경우 + - 중복된 이름이 있는 경우 ''' + if not x: + raise ValueError("자동차 이름이 입력되지 않았습니다.") for i in x: + if not i.strip(): + raise ValueError("자동차 이름은 공백일 수 없습니다.") if len(i) > 5: raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") + if len(x) != len(set(x)): + raise ValueError("자동차 이름은 중복될 수 없습니다.")Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 9-9: expected 2 blank lines, found 1
49-71: 🛠️ Refactor suggestion메인 함수 개선 필요
다음과 같은 개선이 필요합니다:
- 예외 처리 보완
- 변수명을 Python 명명 규칙에 맞게 수정
- while 루프를 for 루프로 단순화
- 시도 횟수 유효성 검사 강화
다음과 같이 수정하세요:
def main(): """ 프로그램의 메인 함수. 자동차 이름과 시도할 횟수를 입력받고, 경주를 진행한 후 우승자를 출력한다. """ - car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') - check_carname(car_name) - - cars = dict.fromkeys(car_name, 0) - - trycount = int(input("시도할 횟수는 몇 회인가요?")) - if trycount == 0: - raise ValueError("시도할 횟수는 0일 수 없습니다") - - count = 0 - while count < trycount: - for i in car_name: - cars[i] += carfoward() - status(cars) - print("") - count += 1 - - winner(cars) + try: + car_names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') + check_carname(car_names) + + cars = dict.fromkeys(car_names, 0) + + try_count = int(input("시도할 횟수는 몇 회인가요?")) + if try_count <= 0: + raise ValueError("시도 횟수는 0보다 커야 합니다") + + for _ in range(try_count): + for name in car_names: + cars[name] += car_forward() + status(cars) + print() + + winner(cars) + except ValueError as e: + print(f"오류: {str(e)}") + except Exception as e: + print(f"예상치 못한 오류가 발생했습니다: {str(e)}")Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 61-61: src/racingcar/main.py#L61
Added line #L61 was not covered by tests🪛 GitHub Actions: Check PEP8 Style
[warning] 56-56: blank line contains whitespace
[warning] 58-58: blank line contains whitespace
[warning] 62-62: blank line contains whitespace
[warning] 70-70: blank line contains whitespace
🪛 GitHub Actions: Check Indentation Depth
[warning] 56-56: Trailing whitespace
[warning] 58-58: Trailing whitespace
[warning] 62-62: Trailing whitespace
[warning] 70-70: Trailing whitespace
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 59-59: src/racingcar/main.py#L59
Added line #L59 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 54-54: Trailing whitespace
[warning] 56-56: Trailing whitespace
[warning] 60-60: Trailing whitespace
[warning] 68-68: Trailing whitespace
[warning] 1-1: Missing module docstring
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[error] 7-7: E302 expected 2 blank lines, found 1
[warning] 54-54: W293 blank line contains whitespace
[warning] 56-56: W293 blank line contains whitespace
[warning] 60-60: W293 blank line contains whitespace
[warning] 68-68: W293 blank line contains whitespace
🔇 Additional comments (5)
src/racingcar/main.py (5)
1-6: 모듈 수준의 문서화 개선 필요현재 모듈 설명이 일반 주석으로 작성되어 있습니다. 파이썬의 문서화 규칙에 따라 docstring으로 변경하는 것이 좋습니다.
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 1-1: Missing module docstring
7-15: 자동차 이름 검증 로직 개선 필요현재 구현은 길이 검증만 수행하고 있습니다. 다음 검증이 추가로 필요합니다:
- 빈 문자열 검증
- 공백 문자 포함 여부 검증
- 중복된 이름 검증
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 7-7: E302 expected 2 blank lines, found 1
17-25: 함수 이름 및 변수명 개선 필요
- 함수 이름에 오타가 있습니다 (carfoward → car_forward)
- 변수명 'a'는 의미를 잘 전달하지 못합니다
28-34: 상태 출력 함수에 대한 테스트 케이스 필요
status함수에 대한 테스트가 누락되어 있습니다. 다음과 같은 테스트 케이스를 추가하는 것이 좋습니다:
- 빈 딕셔너리 입력 시 동작
- 여러 자동차의 상태 출력 정확성
- 진행 거리가 0인 경우의 출력
테스트 코드 작성을 도와드릴까요?
37-44: 우승자 결정 함수에 대한 테스트 케이스 필요
winner함수에 대한 테스트가 누락되어 있습니다. 다음과 같은 테스트 케이스를 추가하는 것이 좋습니다:
- 단일 우승자 케이스
- 공동 우승자 케이스
- 모든 자동차가 같은 거리를 이동한 경우
테스트 코드 작성을 도와드릴까요?
src/racingcar/main.py
Outdated
| def main(): | ||
| """ | ||
| 프로그램의 진입점 함수. | ||
| 여기에서 전체 프로그램 로직을 시작합니다. | ||
| 프로그램의 메인 함수. | ||
| 자동차 이름과 시도할 횟수를 입력받고, 경주를 진행한 후 우승자를 출력한다. | ||
| """ | ||
| # 프로그램의 메인 로직을 여기에 구현 | ||
| print("프로그램이 시작되었습니다.") | ||
| car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | ||
| check_carname(car_name) | ||
|
|
||
| cars = dict.fromkeys(car_name, 0) | ||
|
|
||
| trycount = int(input("시도할 횟수는 몇 회인가요?")) | ||
| if trycount == 0: | ||
| raise ValueError("시도할 횟수는 0일 수 없습니다") | ||
|
|
||
| count = 0 | ||
| while count < trycount: | ||
| for i in car_name: | ||
| cars[i] += carfoward() | ||
| status(cars) | ||
| print("") | ||
| count += 1 | ||
|
|
||
| winner(cars) |
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
메인 함수의 예외 처리 개선 필요
다음과 같은 예외 처리가 추가로 필요합니다:
- 시도 횟수 입력 시 숫자가 아닌 값에 대한 처리
- 음수 시도 횟수에 대한 처리
- 입력 값이 없는 경우(빈 입력)에 대한 처리
예시 구현:
def main():
"""
프로그램의 메인 함수.
자동차 이름과 시도할 횟수를 입력받고, 경주를 진행한 후 우승자를 출력한다.
"""
- car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',')
- check_carname(car_name)
-
- cars = dict.fromkeys(car_name, 0)
-
- trycount = int(input("시도할 횟수는 몇 회인가요?"))
- if trycount == 0:
- raise ValueError("시도할 횟수는 0일 수 없습니다")
+ try:
+ car_input = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").strip()
+ if not car_input:
+ raise ValueError("자동차 이름을 입력해주세요.")
+ car_name = car_input.split(',')
+ check_carname(car_name)
+
+ cars = dict.fromkeys(car_name, 0)
+
+ try_input = input("시도할 횟수는 몇 회인가요?").strip()
+ if not try_input:
+ raise ValueError("시도 횟수를 입력해주세요.")
+ try_count = int(try_input)
+ if try_count <= 0:
+ raise ValueError("시도 횟수는 0보다 커야 합니다.")
+ except ValueError as e:
+ print(f"오류: {str(e)}")
+ returnCommittable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 59-59: src/racingcar/main.py#L59
Added line #L59 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
[warning] 54-54: Trailing whitespace
[warning] 56-56: Trailing whitespace
[warning] 60-60: Trailing whitespace
[warning] 68-68: Trailing whitespace
🪛 GitHub Actions: Check PEP8 Style
[warning] 54-54: W293 blank line contains whitespace
[warning] 56-56: W293 blank line contains whitespace
[warning] 60-60: W293 blank line contains whitespace
[warning] 68-68: W293 blank line contains whitespace
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/racingcar/main.py (1)
2-10: 불필요한 빈 줄 제거 필요모듈 레벨 문서화는 잘 되어 있지만, 불필요한 빈 줄이 있습니다. 가독성을 위해 다음과 같이 수정하세요:
import random """ 자동차 경주 프로그램 이 모듈은 간단한 자동차 경주 게임을 구현합니다. 사용자로부터 자동차 이름을 입력받고, 정해진 횟수만큼 자동차가 전진하는 시뮬레이션을 진행하여 최종 우승자를 출력합니다. -""" - - +"""
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 63-63: src/racingcar/main.py#L63
Added line #L63 was not covered by tests
🔇 Additional comments (6)
src/racingcar/main.py (6)
32-38: 구현이 깔끔합니다!상태 출력 함수가 잘 구현되어 있으며, 문서화도 명확합니다.
62-63: 테스트 커버리지 개선 필요시도 횟수가 0인 경우에 대한 테스트가 누락되어 있습니다. 이 예외 상황에 대한 테스트를 추가해주세요.
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 63-63: src/racingcar/main.py#L63
Added line #L63 was not covered by tests
21-29: 🛠️ Refactor suggestion함수 및 변수 이름 개선 필요
함수 이름에 오타가 있으며, 변수 이름이 의미를 명확히 전달하지 않습니다:
-def carfoward(): +def car_forward(): """ 자동차를 전진시키는 함수. 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. """ - a = random.randint(0, 9) - if a >= 4: + random_number = random.randint(0, 9) + if random_number >= 4: return 1 return 0Likely invalid or redundant comment.
41-48: 🛠️ Refactor suggestion변수 이름을 파이썬 명명 규칙에 맞게 수정 필요
변수 이름을 파이썬의 snake_case 규칙에 맞게 수정하세요:
- maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_forward = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_forward]Likely invalid or redundant comment.
11-18: 🛠️ Refactor suggestion자동차 이름 검증 로직 보완 필요
현재 구현은 이름 길이만 검증하고 있습니다. 다음 검증 사항들을 추가해야 합니다:
def check_carname(x): """ 자동차 이름을 검증하는 함수. - 이름이 5자를 초과할 경우 예외를 발생시킨다. + 이름의 유효성을 검사하고 적절하지 않은 경우 예외를 발생시킨다. """ + if not x: + raise ValueError("자동차 이름이 입력되지 않았습니다.") for i in x: + if not i.strip(): + raise ValueError("자동차 이름은 공백일 수 없습니다.") if len(i) > 5: raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") + if len(x) != len(set(x)): + raise ValueError("자동차 이름은 중복될 수 없습니다.")Likely invalid or redundant comment.
51-73: 🛠️ Refactor suggestion메인 함수의 개선 필요
다음과 같은 개선이 필요합니다:
- 예외 처리 추가
- while 루프를 for 루프로 변경
- 변수 이름 개선
def main(): """ 프로그램의 메인 함수. 자동차 이름과 시도할 횟수를 입력받고, 경주를 진행한 후 우승자를 출력한다. """ - car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') - check_carname(car_name) + try: + car_names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') + check_carname(car_names) - cars = dict.fromkeys(car_name, 0) - trycount = int(input("시도할 횟수는 몇 회인가요?")) + cars = dict.fromkeys(car_names, 0) + try_count = int(input("시도할 횟수는 몇 회인가요?")) - if trycount == 0: - raise ValueError("시도할 횟수는 0일 수 없습니다.") + if try_count <= 0: + raise ValueError("시도 횟수는 0보다 커야 합니다.") - count = 0 - while count < trycount: - for i in car_name: - cars[i] += carfoward() - status(cars) - print("") - count += 1 + for _ in range(try_count): + for name in car_names: + cars[name] += car_forward() + status(cars) + print() - winner(cars) + winner(cars) + except ValueError as e: + print(f"오류: {str(e)}") + except Exception as e: + print(f"예상치 못한 오류가 발생했습니다: {str(e)}")Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 63-63: src/racingcar/main.py#L63
Added line #L63 was not covered by tests
swthewhite
left a comment
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.
전반적으로 잘 하셨습니다.
다만 snake_case가 지켜지지 못한 경우가 좀 있는데, 이를 주시하면서 요구사항에 맞춰 개선해주세요~
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.
Warning
루트에 있는 README.md는 임의로 수정하시면 안됩니다!
원본으로 복구해주시고, 기능 설계서는 docs/README.md로 옮겨주세요!
src/racingcar/main.py
Outdated
| 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. | ||
| """ | ||
| a = random.randint(0, 9) | ||
| if a >= 4: |
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.
숫자상수는, 매직넘버상수로 바꾸고 전방선언 해주는 것이 좋습니다.
| raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") | ||
|
|
||
|
|
||
| def carfoward(): |
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.
snake case로 변경하는 것이 좋아보입니다.
src/racingcar/main.py
Outdated
| # 프로그램의 메인 로직을 여기에 구현 | ||
| print("프로그램이 시작되었습니다.") | ||
| car_name = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | ||
| check_carname(car_name) |
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.
check_car_name으로 하지 않은 이유가 있을까요?
| 최종 우승자를 출력하는 함수. | ||
| 가장 많은 전진을 한 자동차들을 우승자로 표시한다. | ||
| """ | ||
| maxfoward = max(cars.values()) |
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.
snake case로 변경하는 것이 좋아보입니다.
src/racingcar/main.py
Outdated
| check_carname(car_name) | ||
|
|
||
| cars = dict.fromkeys(car_name, 0) | ||
| trycount = int(input("시도할 횟수는 몇 회인가요?")) |
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.
snake case로 변경하는 것이 좋아보입니다.
|
|
||
| # 출력값을 캡처한 후 검증 | ||
| 캡처된_출력 = capsys.readouterr() | ||
| 캡처된_출력 = capsys.readouterr().out |
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.
ㅎㅎ 제가 실수한 부분인데 잘 체크하고 고치셨어요!
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: 5
♻️ Duplicate comments (1)
src/racingcar/main.py (1)
65-66: 🛠️ Refactor suggestion변수명 컨벤션 및 오타 수정 필요
변수명이 snake_case 컨벤션을 따르지 않으며, 'foward' 오타가 있습니다.
- maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_forward = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_forward]
🧹 Nitpick comments (1)
src/racingcar/main.py (1)
2-2: 불필요한 빈 줄 제거 필요PEP8 스타일 가이드에 따라 불필요한 빈 줄을 제거해야 합니다.
import random - """ 자동차 경주 프로그램 이 모듈은 간단한 자동차 경주 게임을 구현합니다. 사용자로부터 자동차 이름을 입력받고, 정해진 횟수만큼 자동차가 전진하는 시뮬레이션을 진행하여 최종 우승자를 출력합니다. """ - -Also applies to: 9-10
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/racingcar/main.py(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Indentation Depth
src/racingcar/main.py
[warning] 79-79: Trailing whitespace
[warning] 85-85: Trailing whitespace
🪛 GitHub Actions: Check PEP8 Style
src/racingcar/main.py
[warning] 79-79: Blank line contains whitespace.
[warning] 85-85: Blank line contains whitespace.
| def carfoward(): | ||
| """ | ||
| 자동차를 전진시키는 함수. | ||
| 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. | ||
| """ | ||
| random_number = random.randint(0, 9) | ||
| if random_number >= 4: | ||
| return 1 | ||
| return 0 |
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
함수명 오타 수정 및 매직 넘버 개선 필요
- 함수명에 오타가 있습니다 ('foward' -> 'forward').
- 매직 넘버(0, 9, 4)를 상수로 정의해야 합니다.
+MIN_RANDOM = 0
+MAX_RANDOM = 9
+FORWARD_THRESHOLD = 4
+
-def carfoward():
+def car_forward():
"""
자동차를 전진시키는 함수.
- 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다.
+
+ Returns:
+ int: 전진 여부 (1: 전진, 0: 정지)
"""
- random_number = random.randint(0, 9)
- if random_number >= 4:
+ random_number = random.randint(MIN_RANDOM, MAX_RANDOM)
+ if random_number >= FORWARD_THRESHOLD:
return 1
return 0📝 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.
| def carfoward(): | |
| """ | |
| 자동차를 전진시키는 함수. | |
| 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. | |
| """ | |
| random_number = random.randint(0, 9) | |
| if random_number >= 4: | |
| return 1 | |
| return 0 | |
| MIN_RANDOM = 0 | |
| MAX_RANDOM = 9 | |
| FORWARD_THRESHOLD = 4 | |
| def car_forward(): | |
| """ | |
| 자동차를 전진시키는 함수. | |
| Returns: | |
| int: 전진 여부 (1: 전진, 0: 정지) | |
| """ | |
| random_number = random.randint(MIN_RANDOM, MAX_RANDOM) | |
| if random_number >= FORWARD_THRESHOLD: | |
| return 1 | |
| return 0 |
| def get_car_names(): | ||
| names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | ||
| check_carname(names) | ||
| return names |
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
함수 문서화 및 입력값 검증 개선 필요
함수에 대한 docstring이 누락되었으며, 입력값에 대한 추가 검증이 필요합니다.
def get_car_names():
+ """
+ 사용자로부터 자동차 이름을 입력받아 검증하고 반환하는 함수
+
+ Returns:
+ list: 검증된 자동차 이름 목록
+ Raises:
+ ValueError: 입력값이 유효하지 않은 경우
+ """
names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',')
+ names = [name.strip() for name in names]
check_carname(names)
return names📝 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.
| def get_car_names(): | |
| names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | |
| check_carname(names) | |
| return names | |
| def get_car_names(): | |
| """ | |
| 사용자로부터 자동차 이름을 입력받아 검증하고 반환하는 함수 | |
| Returns: | |
| list: 검증된 자동차 이름 목록 | |
| Raises: | |
| ValueError: 입력값이 유효하지 않은 경우 | |
| """ | |
| names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') | |
| names = [name.strip() for name in names] | |
| check_carname(names) | |
| return names |
src/racingcar/main.py
Outdated
|
|
||
| for _ in range(try_count): | ||
| for name in car_names: | ||
| cars[name] += carfoward() | ||
| status(cars) | ||
| print() | ||
|
|
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
공백 문자 및 함수 호출 개선 필요
- 불필요한 공백 문자가 있습니다.
- 잘못된 함수명을 사용하고 있습니다.
-
for _ in range(try_count):
for name in car_names:
- cars[name] += carfoward()
+ cars[name] += car_forward()
status(cars)
print()
- 📝 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.
| for _ in range(try_count): | |
| for name in car_names: | |
| cars[name] += carfoward() | |
| status(cars) | |
| print() | |
| for _ in range(try_count): | |
| for name in car_names: | |
| cars[name] += car_forward() | |
| status(cars) | |
| print() |
🧰 Tools
🪛 GitHub Actions: Check Indentation Depth
[warning] 79-79: Trailing whitespace
[warning] 85-85: Trailing whitespace
🪛 GitHub Actions: Check PEP8 Style
[warning] 79-79: Blank line contains whitespace.
[warning] 85-85: Blank line contains whitespace.
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
♻️ Duplicate comments (5)
src/racingcar/main.py (5)
40-48: 🛠️ Refactor suggestion자동차 이동 함수 개선 필요
다음 사항들을 개선해야 합니다:
- 함수명을
car_forward로 변경 (snake_case)- 매직 넘버(0, 9, 4)를 상수로 정의
+MIN_RANDOM = 0 +MAX_RANDOM = 9 +FORWARD_THRESHOLD = 4 + -def carfoward(): +def car_forward(): """ 자동차를 전진시키는 함수. - 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. + + Returns: + int: 전진 여부 (1: 전진, 0: 정지) """ - random_number = random.randint(0, 9) - if random_number >= 4: + random_number = random.randint(MIN_RANDOM, MAX_RANDOM) + if random_number >= FORWARD_THRESHOLD: return 1 return 0
60-67: 🛠️ Refactor suggestion우승자 결정 함수 개선 필요
변수명을 snake_case 컨벤션에 맞게 수정해야 합니다:
maxfoward를max_forward로 변경- maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_forward = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_forward]
24-37: 🛠️ Refactor suggestion이름 검증 함수 개선 필요
다음 사항들을 개선해야 합니다:
- 함수명을
check_car_name으로 변경 (snake_case)- 매개변수명을
names로 변경- 매직 넘버(5)를 상수로 정의
- elif 문을 if 문으로 변경
+MAX_NAME_LENGTH = 5 + -def check_carname(x): +def check_car_name(names): """ 자동차 이름을 검증하는 함수. - 이름이 5자를 초과할 경우 예외를 발생시킨다. + + Args: + names (list): 검증할 자동차 이름 목록 + Raises: + ValueError: 이름이 유효하지 않은 경우 """ - if not x: + if not names: raise ValueError("자동차 이름은 비어있을 수 없습니다.") - for i in x: - if not i.strip(): + for name in names: + if not name.strip(): raise ValueError("자동차 이름은 공백일 수 없습니다.") - elif len(i) > 5: - raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") - if len(x) != len(set(x)): + if len(name) > MAX_NAME_LENGTH: + raise ValueError(f"자동차 이름은 {MAX_NAME_LENGTH}자를 초과할 수 없습니다.") + if len(names) != len(set(names)): raise ValueError("자동차 이름은 중복될 수 없습니다.")
75-84: 🛠️ Refactor suggestion메인 함수 개선 필요
다음 사항들을 개선해야 합니다:
carfoward함수 호출을car_forward로 변경- 불필요한 공백 라인 제거
try: car_names = get_car_names() cars = dict.fromkeys(car_names, 0) try_count = get_try_count() for _ in range(try_count): for name in car_names: - cars[name] += carfoward() + cars[name] += car_forward() status(cars) print() winner(cars)
11-14: 🛠️ Refactor suggestion입력 처리 개선 필요
다음 사항들을 개선해야 합니다:
- 빈 입력 검증 추가
- 입력값 앞뒤 공백 제거
check_carname을check_car_name으로 변경 (snake_case)def get_car_names(): + """ + 사용자로부터 자동차 이름을 입력받아 검증하는 함수 + + Returns: + list: 검증된 자동차 이름 목록 + Raises: + ValueError: 입력값이 유효하지 않은 경우 + """ - names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') + car_input = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").strip() + if not car_input: + raise ValueError("자동차 이름을 입력해주세요.") + names = [name.strip() for name in car_input.split(',')] - check_carname(names) + check_car_name(names) return names
🧹 Nitpick comments (1)
src/racingcar/main.py (1)
3-8: 모듈 문서화 개선 필요모듈 문서화에 다음 내용을 추가하면 좋겠습니다:
- 자동차 이름 제한 사항 (5자 이하, 중복 불가)
- 전진 조건 (4 이상의 무작위 값)
- 우승자 결정 방식
| def get_try_count(): | ||
| count = int(input("시도할 횟수는 몇 회인가요?")) | ||
| if count == 0: | ||
| raise ValueError("시도 횟수는 0보다 커야 합니다.") | ||
| return count |
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
시도 횟수 검증 개선 필요
다음 사항들을 개선해야 합니다:
- 음수 검증 추가
- 숫자가 아닌 입력값 처리
- 빈 입력 검증
def get_try_count():
+ """
+ 사용자로부터 시도 횟수를 입력받아 검증하는 함수
+
+ Returns:
+ int: 검증된 시도 횟수
+ Raises:
+ ValueError: 입력값이 유효하지 않은 경우
+ """
- count = int(input("시도할 횟수는 몇 회인가요?"))
- if count == 0:
+ try_input = input("시도할 횟수는 몇 회인가요?").strip()
+ if not try_input:
+ raise ValueError("시도 횟수를 입력해주세요.")
+ try:
+ count = int(try_input)
+ except ValueError:
+ raise ValueError("시도 횟수는 숫자여야 합니다.")
+ if count <= 0:
raise ValueError("시도 횟수는 0보다 커야 합니다.")
return count📝 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.
| def get_try_count(): | |
| count = int(input("시도할 횟수는 몇 회인가요?")) | |
| if count == 0: | |
| raise ValueError("시도 횟수는 0보다 커야 합니다.") | |
| return count | |
| def get_try_count(): | |
| """ | |
| 사용자로부터 시도 횟수를 입력받아 검증하는 함수 | |
| Returns: | |
| int: 검증된 시도 횟수 | |
| Raises: | |
| ValueError: 입력값이 유효하지 않은 경우 | |
| """ | |
| try_input = input("시도할 횟수는 몇 회인가요?").strip() | |
| if not try_input: | |
| raise ValueError("시도 횟수를 입력해주세요.") | |
| try: | |
| count = int(try_input) | |
| except ValueError: | |
| raise ValueError("시도 횟수는 숫자여야 합니다.") | |
| if count <= 0: | |
| raise ValueError("시도 횟수는 0보다 커야 합니다.") | |
| return count |
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 (6)
src/racingcar/main.py (6)
11-14: 🛠️ Refactor suggestion함수 문서화 및 네이밍 컨벤션 개선 필요
- 함수에 docstring이 누락되었습니다.
check_carname을check_car_name으로 변경하여 Python 네이밍 컨벤션을 따르는 것이 좋습니다.
17-21:⚠️ Potential issue시도 횟수 검증 로직 개선 필요
- 음수 값 검증이 누락되었습니다.
- 숫자가 아닌 입력값에 대한 예외 처리가 필요합니다.
- 함수 문서화(docstring)가 필요합니다.
24-37: 🛠️ Refactor suggestion매직 넘버 및 변수명 개선 필요
- 매직 넘버
5를 상수로 정의해야 합니다.- 파라미터 이름
x를 더 명확한names로 변경하는 것이 좋습니다.elif대신if를 사용하는 것이 더 명확합니다.
40-48: 🛠️ Refactor suggestion함수명 오타 및 매직 넘버 개선 필요
- 함수명의 오타를 수정해야 합니다 (
carfoward→car_forward).- 매직 넘버(
0,9,4)를 상수로 정의해야 합니다.
60-67: 🛠️ Refactor suggestion변수명 컨벤션 및 오타 수정 필요
변수명
maxfoward를max_forward로 변경하여 Python 네이밍 컨벤션을 따르고 오타를 수정해야 합니다.
70-87: 🛠️ Refactor suggestion함수 호출 업데이트 필요
carfoward()호출을car_forward()로 수정해야 합니다.
🧹 Nitpick comments (1)
src/racingcar/main.py (1)
3-8: 모듈 문서화 개선 필요모듈 문서화에 다음 내용을 추가하면 좋겠습니다:
- 주요 함수들의 간단한 설명
- 예외 처리에 대한 설명
- 사용 예시
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md(1 hunks)src/racingcar/main.py(1 hunks)tests/racingcar/test_main.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/racingcar/test_main.py
🔇 Additional comments (2)
src/racingcar/main.py (1)
51-57: 구현이 깔끔합니다!함수가 잘 문서화되어 있고 구현이 명확합니다.
README.md (1)
1-16:⚠️ Potential issueREADME.md 위치 및 내용 개선 필요
- 이 파일은
docs/README.md로 이동해야 합니다.- 기능 목록에 다음 내용을 추가하면 좋겠습니다:
- 각 기능의 구체적인 예시
- 에러 상황에 대한 상세 설명
- 입력값 제한사항에 대한 명확한 설명
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
♻️ Duplicate comments (4)
src/racingcar/main.py (4)
40-48: 🛠️ Refactor suggestion함수명과 매직 넘버 개선이 필요합니다.
- 함수명에 오타가 있습니다 ('foward' -> 'forward').
- 매직 넘버(0, 9, 4)를 상수로 정의해야 합니다.
+MIN_RANDOM = 0 +MAX_RANDOM = 9 +FORWARD_THRESHOLD = 4 + -def carfoward(): +def car_forward(): """ 자동차를 전진시키는 함수. - 0에서 9까지 랜덤값을 생성하여 4 이상이면 1을 반환, 그렇지 않으면 0을 반환한다. + + Returns: + int: 전진 여부 (1: 전진, 0: 정지) """ - random_number = random.randint(0, 9) - if random_number >= 4: + random_number = random.randint(MIN_RANDOM, MAX_RANDOM) + if random_number >= FORWARD_THRESHOLD: return 1 return 0
60-67: 🛠️ Refactor suggestion변수명 컨벤션 개선이 필요합니다.
변수명이 snake_case 컨벤션을 따르지 않습니다.
- maxfoward = max(cars.values()) - winners = [key for key, value in cars.items() if value == maxfoward] + max_forward = max(cars.values()) + winners = [key for key, value in cars.items() if value == max_forward]
11-14: 🛠️ Refactor suggestion입력 검증 로직 개선이 필요합니다.
입력값의 공백을 제거하고 추가 검증이 필요합니다.
def get_car_names(): + """ + 사용자로부터 자동차 이름을 입력받아 검증하는 함수 + + Returns: + list: 검증된 자동차 이름 목록 + Raises: + ValueError: 입력값이 유효하지 않은 경우 + """ names = input("경주할 자동차 이름을 입력하세요.(이름은 쉼표로 구분)").split(',') + if not names: + raise ValueError("자동차 이름을 입력해주세요.") + names = [name.strip() for name in names] check_carname(names) return names
17-21: 🛠️ Refactor suggestion시도 횟수 검증 로직 개선이 필요합니다.
음수 검증과 숫자가 아닌 입력값에 대한 처리가 필요합니다.
def get_try_count(): + """ + 사용자로부터 시도 횟수를 입력받아 검증하는 함수 + + Returns: + int: 검증된 시도 횟수 + Raises: + ValueError: 입력값이 유효하지 않은 경우 + """ - count = int(input("시도할 횟수는 몇 회인가요?")) - if count == 0: + try_input = input("시도할 횟수는 몇 회인가요?").strip() + if not try_input: + raise ValueError("시도 횟수를 입력해주세요.") + try: + count = int(try_input) + except ValueError: + raise ValueError("시도 횟수는 숫자여야 합니다.") + if count <= 0: raise ValueError("시도 횟수는 0보다 커야 합니다.") return count🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 20-20: src/racingcar/main.py#L20
Added line #L20 was not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/racingcar/main.py(1 hunks)tests/racingcar/test_main.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/racingcar/test_main.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/racingcar/main.py
[warning] 20-20: src/racingcar/main.py#L20
Added line #L20 was not covered by tests
[warning] 30-30: src/racingcar/main.py#L30
Added line #L30 was not covered by tests
[warning] 33-33: src/racingcar/main.py#L33
Added line #L33 was not covered by tests
[warning] 37-37: src/racingcar/main.py#L37
Added line #L37 was not covered by tests
🔇 Additional comments (3)
src/racingcar/main.py (3)
1-10: 모듈 문서화가 잘 되어 있습니다.모듈의 목적과 기능이 명확하게 설명되어 있습니다.
51-58: 상태 출력 함수가 잘 구현되어 있습니다.함수의 목적이 명확하고 구현이 간단합니다.
75-87: 메인 함수의 예외 처리가 잘 구현되어 있습니다.예외 처리를 통해 사용자 입력 오류를 적절히 처리하고 있습니다.
단, 다음 라인의 테스트 커버리지가 누락되어 있습니다:
- 20: 시도 횟수가 0인 경우
- 30: 자동차 이름이 비어있는 경우
- 33: 자동차 이름이 공백인 경우
- 37: 자동차 이름이 중복된 경우
테스트 케이스를 추가하시겠습니까?
| def check_carname(x): | ||
| """ | ||
| 자동차 이름을 검증하는 함수. | ||
| 이름이 5자를 초과할 경우 예외를 발생시킨다. | ||
| """ | ||
| if not x: | ||
| raise ValueError("자동차 이름은 비어있을 수 없습니다.") | ||
| for i in x: | ||
| if not i.strip(): | ||
| raise ValueError("자동차 이름은 공백일 수 없습니다.") | ||
| elif len(i) > 5: | ||
| raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") | ||
| if len(x) != len(set(x)): | ||
| 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.
🛠️ Refactor suggestion
함수명과 매직 넘버 개선이 필요합니다.
- 함수명이 snake_case 컨벤션을 따르지 않습니다.
- 매직 넘버(5)를 상수로 정의해야 합니다.
+MAX_NAME_LENGTH = 5
+
-def check_carname(x):
+def check_car_name(names):
"""
자동차 이름을 검증하는 함수.
- 이름이 5자를 초과할 경우 예외를 발생시킨다.
+
+ Args:
+ names: 검증할 자동차 이름 목록
+ Raises:
+ ValueError: 이름이 비어있거나, 공백이거나, 최대 길이를 초과하거나, 중복된 경우
"""
- if not x:
+ if not names:
raise ValueError("자동차 이름은 비어있을 수 없습니다.")
- for i in x:
- if not i.strip():
+ for name in names:
+ if not name.strip():
raise ValueError("자동차 이름은 공백일 수 없습니다.")
- elif len(i) > 5:
- raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.")
- if len(x) != len(set(x)):
+ if len(name) > MAX_NAME_LENGTH:
+ raise ValueError(f"자동차 이름은 {MAX_NAME_LENGTH}자를 초과할 수 없습니다.")
+ if len(names) != len(set(names)):
raise ValueError("자동차 이름은 중복될 수 없습니다.")📝 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.
| def check_carname(x): | |
| """ | |
| 자동차 이름을 검증하는 함수. | |
| 이름이 5자를 초과할 경우 예외를 발생시킨다. | |
| """ | |
| if not x: | |
| raise ValueError("자동차 이름은 비어있을 수 없습니다.") | |
| for i in x: | |
| if not i.strip(): | |
| raise ValueError("자동차 이름은 공백일 수 없습니다.") | |
| elif len(i) > 5: | |
| raise ValueError("자동차 이름은 5자를 초과할 수 없습니다.") | |
| if len(x) != len(set(x)): | |
| raise ValueError("자동차 이름은 중복될 수 없습니다.") | |
| MAX_NAME_LENGTH = 5 | |
| def check_car_name(names): | |
| """ | |
| 자동차 이름을 검증하는 함수. | |
| Args: | |
| names: 검증할 자동차 이름 목록 | |
| Raises: | |
| ValueError: 이름이 비어있거나, 공백일 수 없거나, 최대 길이를 초과하거나, 중복된 경우 | |
| """ | |
| if not names: | |
| raise ValueError("자동차 이름은 비어있을 수 없습니다.") | |
| for name in names: | |
| if not name.strip(): | |
| raise ValueError("자동차 이름은 공백일 수 없습니다.") | |
| if len(name) > MAX_NAME_LENGTH: | |
| raise ValueError(f"자동차 이름은 {MAX_NAME_LENGTH}자를 초과할 수 없습니다.") | |
| if len(names) != len(set(names)): | |
| raise ValueError("자동차 이름은 중복될 수 없습니다.") |
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 30-30: src/racingcar/main.py#L30
Added line #L30 was not covered by tests
[warning] 33-33: src/racingcar/main.py#L33
Added line #L33 was not covered by tests
[warning] 37-37: src/racingcar/main.py#L37
Added line #L37 was not covered by tests
Summary by CodeRabbit
문서
신규 기능
테스트