runtime
89 / 500
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.

Functionorder_cost(subtotal, state, free_from=50)
Taxsubtotal × rate with the state's rate from TAX_RATES; a state not in the table pays no tax
Shipping5.99, free when the subtotal (before tax) is at least free_from
Returnssubtotal + 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
  1. 1O104839 48.89
  2. 2O100043 127.50
  3. 3O101217 24.49

Loading your progress…

Write the order cost once — Python practice · Runtime