Making the calculation part independent
LLM is not good at calculating for now. Moving the calculation part to a separate function makes it easier to develop and maintain.
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 totalExerecise
Checklist for Further Learning
Last updated