+ 오차 원인부터 검증·반올림까지 구체적이다.
- 통화별 정책을 인자로 일반화하지는 않았다.
코드를 입력하면 가독성, 유지보수성, 스타일, 잠재 버그, 성능 개선점과 모범 사례 준수 여부를 구조화해 리뷰합니다.
| 분류 | 개발 › 코딩 |
|---|---|
| 태그 | 분석검토개발자코드 |
Act as a Code Review Assistant. Your role is to provide a detailed assessment of the code provided by the user. You will: - Analyze the code for readability, maintainability, and style. - Identify potential bugs or areas where the code may fail. - Suggest improvements for better performance and efficiency. - Highlight best practices and coding standards followed or violated. - Ensure the code is aligned with industry standards. Rules: - Be constructive and provide explanations for each suggestion. - Focus on the specific programming language and framework provided by the user. - Use examples to clarify your points when applicable. Response Format: 1. **Code Analysis:** Provide an overview of the code’s strengths and weaknesses. 2. **Specific Feedback:** Detail line-by-line or section-specific observations. 3. **Improvement Suggestions:** List actionable recommendations for the user to enhance their code. Input Example: "Please review the following Python function for finding prime numbers: \ndef find_primes(n):\n primes = []\n for num in range(2, n + 1):\n for i in range(2, num):\n if num % i == 0:\n break\n else:\n primes.append(num)\n return primes"
특정 언어와 프레임워크 기준으로 코드 피드백을 받을 때 쓰기 좋다. 코드 분석, 구체 피드백, 개선 제안 형식으로 답하게 되어 있다.
ChatGPT는 정확성·구조·분량의 균형이 가장 좋다. Gemini는 상세하지만 부정확한 예시와 중복이 있고, [C]는 제시되지 않았다.
+ 오차 원인부터 검증·반올림까지 구체적이다.
- 통화별 정책을 인자로 일반화하지는 않았다.
+ 결제 도메인 관점과 대안 코드가 풍부하다.
- 일부 수치 예시가 부정확하고 다소 장황하다.
| 기준 | ChatGPT | Gemini | 앞선 모델 |
|---|---|---|---|
| 지시 준수 | 10 | 9 | ChatGPT +11% |
| 정확성 | 9 | 7 | ChatGPT +29% |
| 구체성 | 10 | 10 | 동점 |
| 구성·가독성 | 10 | 9 | ChatGPT +11% |
| 분량 적정성 | 9 | 7 | ChatGPT +29% |
gpt-5.6-sol가 모델 이름을 가린 채 1~10점으로 채점했습니다 (2026-09-24). 측정값이 아니라 AI 심사 결과입니다.
같은 입력을 세 모델에 넣어 받은 답을 그대로 옮겼습니다. 각 CLI(에이전트 하네스)에서 실행했습니다. ChatGPT·Claude 앱이나 웹에서는 답이 다를 수 있습니다.
[붙여 넣은 자료]
다음 Python 함수를 리뷰해주세요. 장바구니 총액에 할인율을 적용해 최종 결제 금액을 계산하는 함수인데, 가끔 소수점 이하 금액이 이상하게 나온다는 CS 문의가 들어왔습니다.
```python
def calculate_final_price(cart_items, discount_rate):
total = 0
for item in cart_items:
total += item['price'] * item['quantity']
discount = total * discount_rate
final = total - discount
return final
```장바구니 상품별 금액을 합산한 뒤 할인액을 계산하는 구조는 단순하고 이해하기 쉽습니다. 반복문을 통해 여러 상품을 처리하며, 계산 단계도 total → discount → final로 명확합니다.
다만 금액 계산에 Python의 float 또는 일반 숫자 타입을 사용하면 이진 부동소수점 오차가 발생할 수 있습니다. 예를 들어 0.1 + 0.2가 정확히 0.3이 아닌 값으로 계산될 수 있어, 문의하신 “소수점 이하 금액이 이상하게 나오는 현상”의 주요 원인으로 보입니다.
또한 할인율의 단위와 반올림 정책이 명확하지 않고, 잘못된 입력값에 대한 검증도 없습니다.
total = 0item['price']가 실수형이면 이후 계산 전체에 부동소수점 오차가 전파될 수 있습니다.Decimal 또는 최소 화폐 단위인 정수(예: 원 단위)로 관리하는 것이 안전합니다.item['price'] * item['quantity']price, quantity 키가 없으면 KeyError가 발생합니다.item['price']가 float이면 금액 오차가 발생할 가능성이 높습니다.discount = total * discount_ratediscount_rate가 0.1인지 10인지 불분명합니다. 호출자가 10을 전달하면 10배 할인액이 계산됩니다.total * 0.1과 같은 계산에서 부동소수점 오차가 발생할 수 있습니다.final = total - discountROUND_HALF_UP 등)을 명시적으로 적용해야 합니다.return finalfloat인지 Decimal인지 일관되게 처리할 수 있도록 계약을 정하는 것이 좋습니다.Decimal을 사용하는 예시금액과 할인율을 문자열 또는 Decimal로 변환해 계산하고, 최종 결과에서 명시적으로 반올림하는 방식이 적절합니다.
from decimal import Decimal, ROUND_HALF_UP
def calculate_final_price(cart_items, discount_rate):
rate = Decimal(str(discount_rate))
if not Decimal("0") <= rate <= Decimal("1"):
raise ValueError("discount_rate must be between 0 and 1")
total = Decimal("0")
for item in cart_items:
price = Decimal(str(item["price"]))
quantity = item["quantity"]
if price < 0:
raise ValueError("price must not be negative")
if not isinstance(quantity, int) or quantity < 0:
raise ValueError("quantity must be a non-negative integer")
total += price * quantity
final = total * (Decimal("1") - rate)
return final.quantize(Decimal("1"), rounding=ROUND_HALF_UP)
예를 들어 할인율 10%는 0.1로 전달해야 합니다.
calculate_final_price(
[
{"price": "1000", "quantity": 2},
{"price": "500.50", "quantity": 1},
],
"0.1",
)
추가로 다음 사항을 권장합니다.
0.1 + 0.2, 100% 할인, 0% 할인, 빈 장바구니, 잘못된 가격과 수량을 테스트합니다.| 방산 CV 12개월 로드맵 프롬프트 | |
| 2046 퍼즐 게임 제작 프롬프트 | |
| React 컴포넌트 통합 프롬프트 | |
| 3D 아바타 팩토리 요구 프롬프트 | |
| 3D FPS 게임 개발 프롬프트 |