我很麻烦地把我的名单列入我的法典。 这份名单没有归还,而是没有返回,但如果我用利夫声明中的印本来取代返回,则该清单只印制了罚款。 我怎么能够修复?
def makeChange2(amount, coinDenomination, listofcoins = None):
#makes a list of coins from an amount given by using a greedy algorithm
coinDenomination.sort()
#reverse the list to make the largest position 0 at all times
coinDenomination.reverse()
#assigns list
if listofcoins is None:
listofcoins = []
if amount >= coinDenomination[0]:
listofcoins = listofcoins + [coinDenomination[0]]
makeChange2((amount - coinDenomination[0]), coinDenomination, listofcoins)
elif amount == 0:
return listofcoins
else:
makeChange2(amount, coinDenomination[1:], listofcoins)