def largest_first(coins, amount): if type(amount) is not int or amount < 0 or any(type(coin) is not int or coin < 1 for coin in coins): raise ValueError("Positive integer coins and nonnegative amount required") chosen = [] for coin in sorted(coins, reverse=True): while coin <= amount: amount -= coin chosen.append(coin) return chosen, amount chosen, remainder = largest_first([1, 3, 4], 6) print(chosen, remainder) print([3, 3], len([3, 3]) < len(chosen))