capacity = 30
items = [5, 10, 3, 8, 15, 20]
items.sort()
total = 0
count = 0
for weight in items:
if total + weight <= capacity:
total += weight
count += 1
else:
break
print(count)
To embed this project on your website, copy the following code and paste it into your website's HTML: