max_weight = 10
weights = [2, 8, 4, 3, 5]

weights.sort()

total = 0
count = 0

for w in weights:
    if total + w <= max_weight:
        total += w
        count += 1

print(count)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: