AI-Assisted Coding for Developers
Francesca Donadoni
AI Curriculum Manager, DataCamp

def sales_trend(self):
...
if increasing > decreasing:
return "Increasing trend"
else:
return "Decreasing or stable trend"
def sales_trend(self):
"""Analyze sales data to determine the overall trend"""
[...]
User prompt: 為此函式產生一個包含以下內容的 docstring:
Model 的回應:
以下是可直接使用的完整 docstring:
def sales_trend(self):
"""
Analyze the sales data to determine whether there is an increasing trend
or a decreasing/stable trend over time.
[...]
"""
以下是可直接使用的完整 docstring:
def sales_trend(self):
"""
Analyze the sales data to determine whether there is an increasing trend
or a decreasing/stable trend over time.
Parameters
----------
self : object
An object that contains an attribute `daily_sales` (list of int or float),
which represents daily sales values in chronological order.
[...]
"""



以下是整理過的 SalesAnalyzer 類別 README.md 草稿:
SalesAnalyzer
SalesAnalyzer 類別提供簡單方法來分析每日銷售資料,判斷整體趨勢是上升,或下降/持平。此工具適合想快速掌握一段時間銷售表現概況的企業與個人。

(base) datacamp@test:~/datacamp/docstring-generation$ git diff
+
+ Raises:
+ ValueError: If daily_sales contains non-numeric values.
"""
- return sum(self.daily_sales)
+ if not all(isinstance(sale, (int, float)) for sale in self.daily_sales):
+ raise ValueError("All sales figures must be numeric.")
+ return sum(sale for sale in self.daily_sales)


AI-Assisted Coding for Developers