計算ロジックを独立させる
大規模言語モデルは現時点では計算が得意ではありません。計算部分を別の関数に移動することで、開発と保守が容易になります。
Description
Example
def handle_order(order_items):
tax_rate = 0.05
total = 0
for item in order_items:
total += item['price']
total += total * tax_rate
process_payment(total)
ship_order(order_items)
return totaldef calculate_total(order_items, tax_rate=0.05):
subtotal = sum(item['price'] for item in order_items)
total = subtotal + (subtotal * tax_rate)
return total
def handle_order(order_items):
total = calculate_total(order_items)
process_payment(total)
ship_order(order_items)
return totalExercise
Checklist for Further Learning
Last updated