I'm currently trying to write some code which, given a list of coin values, will return all the possible combination of coins summing up to some value. Here's an example of how the program should run:
>>> find_changes(4,[1,2,3])
[[1, 1, 1, 1], [2, 1, 1], [1, 2, 1], [3, 1], [1, 1, 2], [2, 2], [1, 3]]
I was given the following code template to fill out:
def find_changes(n, coins):
if n < 0:
return []
if n == 0:
return [[]]
all_changes = []
for last_used_coin in coins:
### DELETE THE "pass" LINE AND WRITE YOUR CODE HERE
pass
return all_changes
I tried using the following code inside the for
loop:
all_changes.append[last_used_coin]
find_changes(n-last_used_coin,coins)
It's currently not working. What am I doing wrong?