change在python是什么函数_python函数精确更改won'

我的任务是: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

请帮帮我!我错过了什么?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值