用正確提示拆解函式
你在一家城市移動租賃公司的銷售資料分析團隊,該公司提供單車與機車的短期租賃。價格是動態調整的:尖峰時段(上午 7–10 點、下午 5–8 點)不提供折扣;離峰時段則會依據需求與使用量最多下調 40%。
下方的函式會計算價格,並已存於 LLM 可讀取與使用的檔案 pricing.py:
def calc_price(base_price, is_peak, discount_ratio):
if is_peak:
return base_price
return base_price * (1 - 0.4 * discount_ratio)
本練習屬於課程
AI-Assisted Coding for Developers
練習說明
- 提示模型改進此函式的**可讀性與正確性**,包含尖峰與離峰的定價脈絡與**動態定價**情境,並要求將答案以符合 **PEP 8** 規範的 Python 程式碼回傳。
