我的任务是:where the input target_amount is a single non-negative integer value and the input L is a list of positive integer values. Then, exact_change should return either True or False: it should return True if it’s possible to create target_amount by adding up some-or-all of the values in L. It should return False if it’s not possible to create target_amount by adding up some-or-all of the values in L.
For example, L could represent the coins you have in your pocket and target_amount could represent the price of an item – in this case, exact_change would tell you whether or not you can pay for the item exactly.
Here are a few examples of exact_change in action. Notice that you can always make change for the target value of 0, and you can never make change for a negative target value: these are two, but not all, of the base cases!
我写的函数是:def exact_change( target_amount, L ):
if target_amount > sum(L):
return False
elif target_amount == 0:
return True
elif target_amount < 0:
return False
elif target_amount > 0 and L==[]:
return False
elif target_amount == L:
return True
else:
loseit = exact_change(target_amount, L[1:])
useit = exact_change(target_amount, L[0])
return loseit or useit'
结果必须是:
^{pr2}$
但我的结果是:TypeError: 'int' object is not iterable
请帮帮我!我错过了什么?在