question 95 Fundamentals Integration · medium
The most items on a budget
A gift-card holder wants as many items as possible from a wish list for a fixed budget. Buying the cheapest items first gives the most items. Return how many items fit and how much they cost together.
Function
most_items(prices, budget)Returnsa tuple
(count, spent): buy the cheapest items first and stop at the first one that no longer fitsRulesan item that costs exactly what is left still fits;
prices must not changeExamples
callmost_items([12.5, 3.99, 25, 7.25, 4.5], 20)returns(3, 15.74)
callmost_items([10, 10, 10], 25)returns(2, 20)
callmost_items([], 50)returns(0, 0)