question 89 Functions · medium
Write the order cost once
This program prices three orders by pasting the same tax and shipping steps three times, and the copies are about to drift apart. Refactor it: write order_cost(subtotal, state, free_from=50) that returns one order's total, and make the three prints call it. The printed lines must stay exactly the same.
Function
order_cost(subtotal, state, free_from=50)Tax
subtotal × rate with the state's rate from TAX_RATES; a state not in the table pays no taxShipping5.99, free when the subtotal (before tax) is at least
free_fromReturnssubtotal + tax + shipping
Programstill prints the same three lines
Examples
callorder_cost(40, 'CA')returns48.89
callorder_cost(120, 'TX')returns127.5
callorder_cost(18.5, 'OR')returns24.49
Expected output3 lines
- 1O104839 48.89
- 2O100043 127.50
- 3O101217 24.49