Question: make_change(target_amount, L). This function should actually determine which values (fromL) could be returned to total thetarget_amount. That is, instead of simply returningTrueorFalse, yourmake_changefunction should return
make_change(target_amount, L).
This function should actually determine which values (fromL) could be returned to total thetarget_amount.
That is, instead of simply returningTrueorFalse, yourmake_changefunction should returna listof coins taken fromLthat sum up totarget_amount. If there is no such list, thenmake_changeshould simply returnFalse. If there can be more than one possible list of values fromL, then your function may return any one of the valid answers.
Theorderof the values returned does not matter, though it's natural to have them in the same order as they appear in the original list
You do not have to, but you are welcome to useexact_changeas a subroutine (helper function) here!
The examples below show howmake_changeshould work; these are the same arguments as in theexact_changefunction above.
In addition,sortedhas been called, at least on the non-empty feasible cases, so that the results have a well-defined order:
In [1]: sorted(make_change(42, [25, 1, 25, 10, 5, 1])) Out[1]: [1, 1, 5, 10, 25] In [2]: make_change(42, [25, 1, 25, 10, 5]) Out[2]: False In [3]: make_change(42, [23, 1, 23, 100]) Out[3]: False In [4]: sorted(make_change(42, [23, 17, 2, 100])) Out[4]: [2, 17, 23] In [5]: sorted(make_change(42, [25, 16, 2, 15])) Out[5]: [2, 15, 25] In [6]: make_change(0, [4, 5, 6]) Out[6]: [] In [7]: make_change(-47, [4, 5, 6]) Out[7]: False In [8]: make_change(0, []) Out[8]: [] In [9]: make_change(42, []) Out[9]: False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
